A bit more background...
The component scans $this->params and takes into account a number of factors like is the user logged in, are they an administrator, do they perform some other sort of role, where are they in the system, what menu items should have the 'selected' class and so on. It produces a keyed array (e.g. main, sub-1, sub-2, user [log in/log out/logged in as etc] and so on). The array is passed to the view as a variable. The default.ctp layout contains an element that parses each key and renders output.
Currently it's called in app_controller/beforeRender() but this is now being bypassed when the view is cached. It is, by it's nature, very dynamic. It can't easily be created in full in advance and placed in session because, for example, a user could log in and then log out.
Jeremy Burns
Class Outfit
jeremyburns@classoutfit.com
(t) +44 (0) 208 123 3822
(m) +44 (0) 7973 481949
Skype: jeremy_burns
http://www.classoutfit.com
On 31 May 2011, at 15:58, dreamingmind wrote:
> Jeremy,
>
> I don't know details of how to accomplish this, but it seems like
> you're going to have to call another non-cached action instead of the
> action you want. It will:
>
> - call the navigation engine to get an html fragment of your menus
> - call the desired action and get the page rendering
> - plug the menus into the page and send it to the browser
>
> or
>
> - send the menu out as a string that javascript can insert in the page
> once it loads
>
> Does this seem possible?
>
> Regards,
> Don
>
> On May 31, 5:44 am, Jeremy Burns <jeremybu...@classoutfit.com> wrote:
>> I've raised a similar question before but got no responses, so I'll
>> try something more specific.
>>
>> I have an application that is pretty dynamic. With no caching turned
>> on there is a lag of around 2 seconds before anything happens, and
>> then it all zips in really quickly. If I blanket enable view caching
>> (enabling cache in core.php, adding the Cache helper to app_controller
>> and setting cacheAction to +1hour) the lag disappears, response is
>> fantastic but the results are (understandably) terrible as nothing is
>> dynamic.
>>
>> If I move the cache setting from app_controller into specific actions
>> I start to get better results. It's a pretty big app, so that's going
>> to take a lot of time and testing to do correctly. However, I have a
>> particular problem that I need to solve before I put in the effort.
>>
>> I have a navigation component that reads $this->params, sets up some
>> variables that are passed through the controller and rendered in an
>> element (that also has a nested element):
>>
>> function beforeRender() {
>> $this->set('menus', $this->Navigation->menus($this->params));
>>
>> I have placed <cake:nocache></cake:nocache> blocks in the elements.
>>
>> Reading the Cake on line book:
>> "It should be noted that once an action is cached, the controller
>> method for the action will not be called - otherwise what would be the
>> point of caching the page. Therefore, it is not possible to wrap
>> <cake:nocache> </cake:nocache> around variables which are set from the
>> controller as they will be null."
>>
>> As every page contains the navigation code, it would seem that I
>> cannot pass the menus variable down. Subsequent rendering of the
>> navigation (when the contents have changed) delivers lots of
>> 'Undefined index' errors as the variables are indeed missing. This is
>> especially so when a user logs in and then logs, which generates
>> different menu content.
>>
>> Can anyone suggest a work around for this?
>
> --
> 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
--
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:
Post a Comment