本文实例讲述了Thinkphp5.0 框架实现控制器向视图view赋值及视图view取值操作。分享给大家供大家参考,具体如下:
Thinkphp5.0 控制器向视图view的赋值
方式一(使用fetch()方法的第二个参数赋值):
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
public function study_view(){
return $this->fetch('study_view',[
'id' => 1,
'name' => 'li lei',
'age' => 10
]);
}
}
方法二(使用assign()方法赋值):
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
public function study_view(){
$this->assign('id',1);
$this->assign('name','li lei');
$this->assign('age','12');
return $this->fetch();
}<