视图实例化
有三种办法 建议头两个就行,记得建立view里面的文件
<?php
namespace app \index \controller ;
use think \Controller ;
class Index extends Controller
{
public function index ()
{
return $this -> fetch();
return view();
}
}
视图赋值
$this ->assign('name' ,'ThinkPHP' );
$this ->assign('email' ,'thinkphp@qq.com' );
$this ->assign([
'name' => 'ThinkPHP' ,
'email' => 'thinkphp@qq.com'
]);
return $this ->fetch('index' );
return $this ->fetch('index' , [
'name' => 'ThinkPHP' ,
'email' => 'thinkphp@qq.com'
]);
return view('index' , [
'name' => 'ThinkPHP' ,
'email' => 'thinkphp@qq.com'
]);
输出替换,模板替换
配置文件修改,意思是,全部都可以使用,在config.php里面
'view_replace_str' => [
'__PUBLIC__' =>'/public/' ,
'__ROOT__' => '/' ,
]
return view('index' ,['name' =>'thinkphp' ],['__PUBLIC__' =>'/public/' ]);
return $this ->fetch('index' , [
'name' => 'ThinkPHP' ,
'email' => 'thinkphp@qq.com'
],['__PUBLIC__' =>'/public/' ]);