本文实例讲述了thinkPHP5框架渲染模板的3种方式。分享给大家供大家参考,具体如下:
默认情况下,控制器的输出全部采用return的方式,无需进行任何的手动输出,系统会自动完成渲染内容的输出。
在控制器里渲染模板
namespace appindexcontroller;
use thinkview;
class Index{
public function index(){
$view = new view();
return $view->fetch('index');
}
}
直接使用view助手函数渲染模板
namespace appindexcontroller;
class Index{
public function index() {
return view('index');
}
}
继承thinkController类
如果继承了thinkController类,就可以直接调用thinkView及thinkRequest类的方法。例子:
namespace appindexcontroller;
use thinkController;
class Index extends Controller{
public function index(){
$this->assign('domain', $this->request->url(true));
return $this->fetch('index');
}
}