二、輸出模闆内容 (重點)
a、display
1.display中沒有參數 $this->display();
2.可以帶參數 $this->display(本子產品檔案夾下的其他模闆檔案); $this->display('index2');
$this->display(其他檔案夾下的模闆檔案); $this->display('Public:error');//注意,僅僅需要在Tpl下有Public檔案夾以及其中的error.html即可,不需要一定有Public子產品
$this->display(其他主題下的 檔案夾下的 模闆檔案);//需要開啟主題支援 $this->display('my:Index:index');
$this->display(一個url路徑); $this->display('./Public/error.html');
$this->display('./Public/error.html','utf-8','text/xml');
$this->show($content);
3.fetch方法 獲得模闆檔案中的内容,以字元串形式傳回 $content=$this->fetch('Public:error');
4.show方法 不需要模闆檔案,可以直接輸出模闆内容 $content=$this->fetch('Public:error'); dump($content); $content=str_replace('h1','i',$content); $this->show($content);
三、模闆中的指派 (重點)
//$this->assign('name','趙桐正'); $this->name='趙桐正2'; $this->display();
四、模闆替換 (重點)
__PUBLIC__:會被替換成目前網站的公共目錄 通常是 /Public/
__ROOT__: 會替換成目前網站的位址(不含域名)
__APP__: 會替換成目前項目的URL位址 (不含域名)
__GROUP__:會替換成目前分組的URL位址 (不含域名)
__URL__: 會替換成目前子產品的URL位址(不含域名)
__ACTION__:會替換成目前操作的URL位址 (不含域名)
__SELF__: 會替換成目前的頁面URL
更換模闆變量規則,修改配置項 'TMPL_PARSE_STRING'=>array( //添加自己的模闆變量規則 '__CSS__'=>__ROOT__.'/Public/Css', '__JS__'=>__ROOT__.'/Public/Js', ),