本文實(shí)例講述了thinkPHP5框架渲染模板的3種方式。分享給大家供大家參考,具體如下:
默認(rèn)情況下,控制器的輸出全部采用return的方式,無需進(jìn)行任何的手動輸出,系統(tǒng)會自動完成渲染內(nèi)容的輸出。
在控制器里渲染模板
namespace app/index/controller;use think/view;class Index{ public function index(){ $view = new view(); return $view->fetch('index'); }}直接使用view助手函數(shù)渲染模板
namespace app/index/controller;class Index{ public function index() { return view('index'); }}繼承think/Controller類
如果繼承了think/Controller類,就可以直接調(diào)用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'); }}希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選