批改狀態(tài):未批改
老師批語:
public function test2() { $name = 'www'; //assign('模版中變量名稱','值') //return $this->view->assign('name',$name)->fetch(); //傳參賦值fetch //return $this->view->fetch('index@index/test2',['name'=>$name]); //對象賦值 $this->view->name = 20; return $this->view->fetch(); }
//模版過濾與替換 public function test3() { //tp5.1刪除了替換功能 采用config\template.php $this->view->name = 'zzz'; //$filter = function ($content){//過濾函數(shù),參數(shù)聲明傳入模版內(nèi)容 // return str_replace('name','eee',$content);//將name替換成eee,$content=傳入的模版內(nèi)容,執(zhí)行時,會將當(dāng)前模板內(nèi)容自動讀取變量中 //}; //return $this->filter($filter)->fetch(); return $this->filter(function ($content){//過濾函數(shù),參數(shù)聲明傳入模版內(nèi)容 return str_replace('name','eee',$content);//將name替換成eee,$content=傳入的模版內(nèi)容,執(zhí)行時,會將當(dāng)前模板內(nèi)容自動讀取變量中 })->fetch(); }
//模版繼承 public function test5() { return $this->view->fetch(); }
{//繼承模版中只允許block標(biāo)簽base.html} {block name="header"} {include file="publick/header"/} {/block} {block name="body"} 主體部分 {/block} {block name="course"} 我是course中的 {/block} <p>在父模版中block之外的正常輸出子模版則不會輸出</p> {block name="footer"} {include file="publick/footer"/} {/block}
{extend name="base"/} {//將父模版中的body進(jìn)行重寫,我是test5.html} {block name="body"} <h1>我是模版的網(wǎng)站主體</h1> {/block} {block name="course"} {__block__}course模塊 {/block}
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號