PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

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

原创
2016-06-13 10:55:20 602浏览

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 即可

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。