当前位置: 代码迷 >> PHP >> cakephp工作笔记20110601_控制器中访问其余控制器方法
  详细解决方案

cakephp工作笔记20110601_控制器中访问其余控制器方法

热度:98   发布时间:2016-04-28 23:15:29.0
cakephp工作笔记20110601_控制器中访问其他控制器方法
requestAction(string $url, array $options)

This function calls a controller's action from any location and returns data from the action. The $url passed is a CakePHP-relative URL (/controllername/actionname/params). To pass extra data to the receiving controller action add to the $options array.
You can use requestAction() to retrieve a fully rendered view by passing 'return' in the options: requestAction($url, array('return'));. It is important to note that making a requestAction using 'return' from a controller method can cause script and css tags to not work correctly.

If used without caching requestAction can lead to poor performance. It is rarely appropriate to use in a controller or model.

requestAction is best used in conjunction with (cached) elements – as a way to fetch data for an element before rendering. Let's use the example of putting a "latest comments" element in the layout. First we need to create a controller function that will return the data.
When an action is called through requestAction $this->params['requested'] is set to 1 as an indicator. So checking that you can either return the required data else set it a view variable like you normally would. This helps keep things DRY.
例子:
在air_status控制器中调用stores_houses的方法shlistdir
function airscene()
{
$this->layout = "iframe";
$rs = $this->requestAction('/stores_houses/shlistdir');
$this->set('test',$rs);
}


隐藏GridPanel表头上的排序下拉菜单

文章分类:Web前端
写道
gridPanel的配置项里加上 enableHdMenu :false  即可
  相关解决方案