Yaf_Controller_Abstract::display
(Since Yaf 1.0.0.5)
public boolean Yaf_Controller_Abstract::display( string $action ,
array $tpl_vars
= NULL );
渲染视图模板, 并直接输出渲染结果
![]() |
注意 |
|---|---|
| 此方法是对Yaf_View_Interface::display的包装 |
例 11.54. Yaf_Controller_Abstract::display 的例子
<?php
class IndexController extends Yaf_Controller_Abstract {
public funciton init() {
/* 首先关闭自动渲染 */
Yaf_Dispatcher::getInstance()->disableView();
}
public function indexAction() {
$this->initView();
/* 自己输出响应 */
$this->display("test.phtml", array("name" => "value"));
}
}
?>
通过$tpl_vars传入的变量只对本次渲染生效, 并且会覆盖通过Yaf_View_Interface::assign分配的同名变量. 对于上面的例子, 对应的模板可以写成:
例 11.95. Yaf_Controller_Abstract::display 模板的例子
<!-- application/views/test.phtml -->
<ul>
<?php foreach ($products as $product) { ?>
<li><?php echo $product; ?></li>
<?php } ?>
</ul>