控制器文件——分配变量
方式一:使用think\Controller中的fetch方法
namespace app\index\controller;
use think\Controller;
class Index extends Controller{
public function index(){
return $this->fetch('index',[
'email' => '1111111111@qq.com',
'username' => 'dobby'
]);
}
}
方式二:使用think\Controller中的assign方法
namespace app\index\controller;
use think\Controller;
class Index extends Controller{
public function index(){
$this->assign('email','11111111111@qq.com');
$this->assign('username','dobby');
return $this->fetch('index');
}
}
方式三:使用think\Controller中的$this->view
namespace app\index\controller;
use think\Controller;
class Index extends Controller{
public function index(){
$this->view->email = '1111111111@qq.com';
$this->view->username = 'dobby';
return $this->fetch('index');
}
控制器文件代码:
namespace app\index\controller;
use think\Controller;
class Index extends Controller{
public function index(){
session('email','1111111111@qq.com');
cookie('username','dobby');
return $this->fetch('index');
}
} 常量输出
控制器文件:
namespace app\index\controller;
use think\Controller;
class Index extends Controller{
public function index(){
$this->assign('email','2222222222@qq.com');
$this->assign('username','dobby');
$this->assign('time',time());
return $this->fetch('index');
}
}
控制器文件:
namespace app\index\controller;
use think\Controller;
class Index extends Controller{
public function index(){
$this->assign('a',10);
$this->assign('b',20);
$this->assign('c',5);
return $this->fetch('index');
}
}