cakePHP布局数据,使用requestAction,还有另一种方法吗? [英] cakePHP layout data, using requestAction, is there another way?

查看:43
本文介绍了cakePHP布局数据,使用requestAction,还有另一种方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是一个已知问题,requestAction是一种资源浪费。但是,我需要一些默认布局中的动态数据。我正在为此使用元素,并带有requestAction调用。

这是唯一的方法吗?

I'ts a known issue, requestAction is a resource waste. however, I need some dynamic data in my default layout. I'm using elements for it, with requestAction calls.
Is it the only way?

推荐答案

requestAction没什么问题,低效率地调用它并提高应用程序的性能非常容易。它的工作方式将最终导致带有属性的怪物对象膨胀等,这些都是您不需要的东西,如果您意识到这样的事情可能就不会拉扯。如果有多少开发人员不花三秒钟的时间键入$ this-> Other-> Model->,如果它使您免于潜在地调试那些庞然大物之一的话,

There's nothing wrong with requestAction, it's just very easy to invoke it inefficiently and skewer your app's performance. The way it works, you'll end up with monster objects bulging with properties, etc - stuff you don't need and probably wouldn't have pulled if you'd realized it was going to happen like that. How many devs wouldn't spend three extra seconds to type $this->Other->Model-> if it saved you from potentially trying to debug one of those behemoth objects?

85(满分100),有一种更有效的(应用程序性能)方法来执行您需要requestAction()进行的操作。实际上,cake中还内置了另一种方法,几乎​​可以完成相同的操作,只是要在控制器中使用它,如果可以找到它,就可以链接...

85 times out of 100, there's a more efficient (app performance) way to do whatever you needed requestAction() to do. There's actually another method built into cake that does almost the same thing, only it's meant to be used in controllers and if I can find it, I'll link...

编辑我似乎找不到。有点晦涩难懂。

Edit I can't seem to find it. It's something a little extra obscure.

回答/建议您的问题,避免requestAction在视图/元素中特别容易。

Answer / suggestion to your question, avoiding requestAction is especially easy in views / elements.

如果有数据不是那么抽象,而是更具动态性,ajax->调用您的控制器/方法,传递任何数据,等等,获取动态结果。

If the data is less abstract and more dynamic, ajax -> call your controller / method, pass any data, etc, fetch your dynamic result.

如果数据是高度抽象或适用的-以便在默认布局中需要它-考虑将其塞入AppController甚至引导程序中。

If the data is highly abstract or applicable - such that you need it in your default layout - consider tucking it into your AppController or even the bootloader. This is probably a much more efficient solution - pushing it from the process stage rather than paddling upstream to get it at the rendering stage.

当然,组件/帮助程序会从处理阶段将其推向上游,而不是向上游进行填充。是定位多控制器+布局级视图数据获取的另一种方式。

Components / helpers, of course, would be another way to position multiple-controller + layout-level view data fetching.

HTH :)

这篇关于cakePHP布局数据,使用requestAction,还有另一种方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆