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 即可
分享到:
相关推荐
控制器中的动作(Action)对应着特定的URL请求,当请求与控制器的动作匹配时,CakePHP的请求分发器会调用相应动作完成处理。开发者可以创建自定义的控制器并继承自AppController,AppController是所有控制器的基类,...
- **控制器创建**:通过URL路由解析调用特定控制器的方法。 - **视图模板**:控制器负责处理数据并传递给视图层展示。 - **视图模板与项目整合**:在视图目录下创建与控制器同名的子目录存放模板文件。 #### 五、...
然后,通过配置路由,可以访问到相应的控制器和方法。例如,通过`http://web.0507shop.com/index.php?r=site/index`,我们可以访问到名为`site`的控制器的`index`方法。 在与商城模板结合的过程中,Yii的MVC架构起...
3. **控制器(Controller)**:控制器处理用户的请求,调用模型进行数据处理,并将结果传递给视图进行渲染。 4. **路由器(Router)**:路由器解析URL,确定哪个控制器和动作应该处理请求。 5. **助手(Helper)**...
CakePHP,一个基于MVC(模型-视图-控制器)架构的PHP框架,就内置了一个强大的ORM系统,即CakePHP ORM。这个“cakephp-orm-notes”项目,正如其标题所示,是一个关于如何有效利用CakePHP ORM的实践指南。 首先,让...
- **目的**:提高应用程序性能,减少对数据库或其他后端服务的访问频率。 - **策略**: - 按小时时间间隔缓存:定期更新缓存数据。 - 按天间隔缓存:每天固定时间刷新缓存。 #### 六、数据解析 - **XML解析**:...
来自简单Acl控制的应用程序 还有一个来自的管理插件 CakePHP是PHP的快速开发框架,它使用Active Record,关联数据映射,Front Controller和MVC等众所周知的设计模式。我们的主要目标是提供一个结构化的框架,使所有...
4. **路由与控制器**:如何在框架中设置路由,定义控制器,以及处理HTTP请求和响应。 5. **模板引擎**:如Blade(Laravel)、Twig(Symfony)等,如何编写和渲染视图模板。 6. **数据库操作**:ORM(对象关系映射...