yaf视图

Yaf默认是开启了自动渲染,所以建了action后,他就会自己找模板!在测试的时候,如果不想让他寻找模板可以在action中return false 或者在bootstrap.php中关闭渲染

Yaf_Dispatcher::getInstance()->autoRender(false); 
或者
$dispatcher->getInstance()->disableView();

默认模板文件后缀为phtml,想修改就在application.ini中配置一下就OK

application.view.ext = "html"

自动渲染时模板文件路径:
application下views下控制器目录名下的action.phtml

如果是模块的时候,路径为
application下modules下views下控制器目录名下的action.phtml

其它参数 (控制器中使用)
assign 相当于变量赋值

$this->getView()->assign('user','lvtao'); //模板文件中直接用php语法输出

render 渲染结果

echo $this->getView()->render('User/index.phtml');

display 渲染并输出

$this->getView()->display('User/index.phtml');

setScriptPath 设置模板的基目录

$this->getView()->setScriptPath('/template/index.phtml');

getScriptPath 获取当前模板路径 直接输出,不需要参数
__set 为视图引擎分配一个模板变量, 在视图模板中可以直接通过${$name}获取模板变量值

 $this->getView()->name = "value";

__get 获取视图引擎的一个模板变量值

echo $this->_view->name;

get 获取视图引擎的一个模板变量值

echo $this->_view->get("name");
原文地址:https://www.cnblogs.com/wangshuyi/p/7099646.html