Thursday, June 28, 2012

Re: Is there a lighter weight alternative to requestAction?

Hello,

Another way to do this is to have one controller requestAction to fetch (as array or objects) all the data you need to render your modules, then using Elements or View Blocks to do the actual rendering of the modules.

For example in your AppController beforeFilter method  you could have something like:

$this->requestAction( "/modules/loadData/$currentController/$currentAction").

and the "loadData" action in the "modules" controller would load and set all the required data for the modules on the requested page. It could even load and set a list of elements and positions to be rendered into!

Next in your view (or layout) render this module data you've just loaded, around the main view of the requested action.

So, even very complex websites can be modeled as a MVC, but the model becomes much more complex (like a list of modules, page elements and so on) as opposed of a single table associated with a controller.

With a smart use of the caching system this should work fine.

In conclusion, redesign the app so that you will get all the data you need with only ONE requestAction...

PS: Thinking about this more deeply, I believe that with a smart usage of AppController:beforeFilter, you may not even need to use requestAction at all. You could instead fetch everything you need directly from the AppController.

On Thursday, June 28, 2012 9:25:06 PM UTC+3, Mark Wratten wrote:
That's the dilemma we are facing. The traditional MVC paradigm where a URL maps to a controller and action is fine for simple sites, but for more complex sites the model falls apart. Our site started as a straightforward MVC design, but then the users wanted to add their own landing pages and control what appears on each page. It is not practical to create a new controller/action/view for each new landing page so the site became a hybrid of traditional MVC and a CMS with the ability to embed active content.

@Florian, that's essentially what we are doing. For the updated design, we are routing all requests to a single controller/action/view and using a Helper to embed modules in the content. The module positions are represented by tokens in the content, so we don't know which modules to load until rendering the view. As most of the modules are active content we need to use requestAction to assemble the module content from data in the database and render in the view. Because requestAction loads a new environment it adds a significant overhead especially when loading a lot of modules. And it also involves a bit of a kludge to change the routing on the fly. It is working, but I feel it could be done in a cleaner, simpler, more efficient way, but I am struggling how to figure out how to do that and stay within the Cake paradigm.

Mark

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: