thinkPHP5框架渲染模板有哪些

这篇文章将为大家详细讲解有关thinkPHP5框架渲染模板有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

具体如下:

默认情况下,控制器的输出全部采用return的方式,无需进行任何的手动输出,系统会自动完成渲染内容的输出。

在控制器里渲染模板

namespace app\index\controller;
use think\view;
class Index{
 public function index(){
  $view = new view();
  return $view->fetch('index');
 }
}

直接使用view助手函数渲染模板

namespace app\index\controller;
class Index{
 public function index() {
  return view('index');
 }
}

继承think\Controller类

如果继承了think\Controller类,就可以直接调用think\View及think\Request类的方法。例子:

namespace app\index\controller;
use think\Controller;
class Index extends Controller{
 public function index(){
  $this->assign('domain', $this->request->url(true));
  return $this->fetch('index');
 }
}

关于“thinkPHP5框架渲染模板有哪些”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。