On Fri, Apr 15, 2011 at 11:38 AM, Brian Sweeney <eclecticg...@gmail.com> wrote: > On Thu, Apr 14, 2011 at 2:49 PM, cricket <zijn.digi...@gmail.com> wrote: > >> function startup(&Controller) >> { >> $this->Controller = $Controller; >> } > > I don't have anything like the startup function (I assume that's part of the > default controller class?).
It's a component method. There are 2 methods that are called for each component, both receiving the controller as a parameter. initialize: Called before the Controller::beforeFilter(). startup: Called after the Controller::beforeFilter() and before the controller action http://api.cakephp.org/class/component So, the example I posted earlier shows how to maintain a handle on the controller so as to call its methods. > But yes, this is how I'm passing variables to > the view. Except in some of the non-cached code where I'm using > requestAction() to get data I need. But requestAction() is a horrible performance hog so hopefully you'll get all of this sorted out enough where you no longer (think you) need it. >> >> It's more to do with how the loop is being parsed. Put the nocache >> tags outside of the loop. > > I'd like to place the nocache tags around the whole loop, but this is where > my simplified example breaks down. The loop contains both cacheable and > non-cacheable content. I guess a good analogy to my page would be a product > list where next to each product is an icon indicating whether or not you've > placed it in your cart. So my loop actually looks closer to this (again, > somewhat simplified): > > <?php > echo '<table>'; > foreach ($products as $product) { > echo '<tr><td>', $product['Product']['name'] , '</td><td>'; > echo (in_array($product['Product']['id'], $user_cart_items) ? 'Yes' : > 'No'); > echo '</td></tr>'; > } > echo '</table>'; > ?> > > So what I want to do is place the nocache tags around the Yes/No echo inside > the foreach loop. As I mentioned in an earlier email I was able to work > around my particular issue by using page elements. I'm also working around > one of the limitations in view caching by echoing out some PHP code so that > I can pass the current product id to my page component. So a functional > caching example based using the code from above would look like this: > > <?php > echo '<table>'; > foreach ($products as $product) { > echo '<tr><td>', $product['Product']['name'] , '</td><td>'; > $product_id = $product['Product']['id']; > echo "<?php $product_id = $product_id; ?>"; ?><cake:nocache><?php > echo $this->element('cart-control', array('product_id' => $item_id, > 'user_cart_items' => $user_cart_items)); ?></cake:nocache><?php > echo '</td></tr>'; > } > echo '</table>'; What the heck is this?! echo "<?php $product_id = $product_id; ?>"; ?> I think you should maybe consider not caching this view. That might be simplest. > $user_cart_items is instantiated at the top of the page in a nocache block. > Ugly and confusing, yes? But it works. ;) > > Since I do have some code that works with the loop, the discussion is mostly > academic as far as that problem is concerned. If it's academic, I'm afraid I'd have to give you a D. Your interpretation of how view caching *should* work is not realistic. -- 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