批改状态:未批改
老师批语:
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){//过滤函数,参数声明传入模版内容 // return str_replace('name','eee',$content);//将name替换成eee,$content=传入的模版内容,执行时,会将当前模板内容自动读取变量中 //}; //return $this->filter($filter)->fetch(); return $this->filter(function ($content){//过滤函数,参数声明传入模版内容 return str_replace('name','eee',$content);//将name替换成eee,$content=传入的模版内容,执行时,会将当前模板内容自动读取变量中 })->fetch(); }
//模版继承 public function test5() { return $this->view->fetch(); }
{//继承模版中只允许block标签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进行重写,我是test5.html} {block name="body"} <h1>我是模版的网站主体</h1> {/block} {block name="course"} {__block__}course模块 {/block}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号