On Thu, Apr 14, 2011 at 11:00 AM, Brian Sweeney <eclecticg...@gmail.com> wrote: > I think even though some of the content is state-sensitive the page could > still benefit from view caching. It does present some difficulties, though, > which is why I'm here. > > But even if I take out the state-sensitive aspects of the page I'm still > running into user-specific inconsistencies in the cached view. The worst > example is if I access the page initially as an admin vs. normal user. The > cached page is completely broken in the latter case, but works fine in the > former.
<cake:nocache> <?php if ( (bool) $this->Session->read('Auth.User.admin') ) { echo $this->element('comments/list_admin'); } else { echo $this->element('comments/list'); } ?> </cake:nocache> > Perhaps. I'd like to know more about the caching process, though, so I have > a better feel for what's possible and what's not. This seems like a bug to > me because the nocache content is being cached after the first iteration. > But I realize it could also just be a limitation of how the document is > parsed. It's more to do with how the loop is being parsed. Put the nocache tags outside of the loop. > But can I access, for example, the authentication component? I pass along > the instantiation to the view (i.e. $this->set('Auth', $this->Auth)) so that > I can display some restricted content inline on the page. When a user logs in, Auth saves the User record to the session with the key Auth.User. In a controller, you access this with: $this->Auth->user('field_name') In a view: $this->Session->read('Auth.User.field_name') To check whether the user is logged in: if ($this->Session->read('Auth.User.id')) { } > Perhaps this is something I should be looking at admin routing for? I > haven't really looked into that functionality yet. Admin routing may be pertinent here but I couldn't say without seeing an example. > Sorry, I meant component-instantiated variables. Though, as I mentioned > above, I'm also doing some things with the auth component in the view. > Should I be accessing this information by another means? Variables to be handed to the view are set() in the controller. In a component: $this->Controller->set('foo', 'bar'); Assuming your component has something like: public $Controller; function startup(&Controller) { $this->Controller = $Controller; } > I'll be back later today with some more concrete examples. I'm going to hack > at it a little more this morning and see what comes of things. > >> >> [1] But see here: >> >> http://nuts-and-bolts-of-cakephp.com/2011/02/05/make-your-cakephp-app-ridiculously-faster-with-view-caching/ > > One of my first find when I started doing this ;) Teknoid's site is an excellent resource. I've learned lots from it. Be aware, though, that Cake has changed a lot in the past couple of years. So info you find online may be outdated sometimes. -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php