CakeFest 2024: The Official CakePHP Conference

Yaf_Dispatcher::autoRender

(Yaf >=1.0.0)

Yaf_Dispatcher::autoRender开启/关闭自动渲染

说明

public Yaf_Dispatcher::autoRender(bool $flag = ?): Yaf_Dispatcher

Yaf_Dispatcher 将会在分发到来的请求后自动渲染,可以带 flag true 调用此方法来阻止渲染。

注意:

也可以在操作中简单的返回 false 来阻止动作的自动渲染

参数

flag

bool

注意:

自 2.2.0 起。如果没有指定此参数,则会返回当前状态

返回值

示例

示例 #1 Yaf_Dispatcher::autoRender() 示例

<?php
class IndexController extends Yaf_Controller_Abstract {
/* init method will be called as soon as a controller is initialized */
public function init() {
if (
$this->getRequest()->isXmlHttpRequest()) {
//do not call render for ajax request
//we will outpu a json string
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
}
}

}
?>

以上示例的输出类似于:


add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top