Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting active page when Zend_Navigation is cached?
    primarykey
    data
    text
    <p><strong>Update</strong> - Please see update below.</p> <p>I'm attempting to improve the performance of our ZF based CMS, and am trying out caching the <code>Zend_Navigation</code> object I create with the menu structure. Caching the object means I can't set the current page to active, or I'll have a copy of the menu in the cache for every page. </p> <p>To allow caching of the structure, regardless of current page, I've moved highlighting of the current page in the menu to jQuery, which is working well. Then I noticed that the <code>Breadcrumb_Helper</code> (which uses the same <code>Zend_Navigation</code> object as the menu) wasn't displaying anything - obviously because I haven't got a page set to active.</p> <p>Given I know the id of the page, is there a way to get inside the <code>Zend_Navigation</code> object to set that particular one to active?</p> <p>Ideally I'd like to do something like: </p> <pre><code> $nav-&gt;findOneBy("id", $currentPageId)-&gt;setActive(true); </code></pre> <p>But there doesn't seem to be a way to access the pages in the object like this. Looking at the code, using <code>findOneBy</code> to get the current page, then <code>removePage</code> to remove it, then setting the collected one to active, and using <code>addPage</code> to put the collected, updated one back in might be an option, but rather convoluted.</p> <p>The other option is just to cache the array I use to construct the <code>Zend_Navigation</code> object, which would be easier to set the current page to active, after getting the base array from the cache.</p> <p>(I should point out that all the pages in the cms just have urls like <code>/privacy</code>, <code>/about-us</code>, and are routed to a default frontend module, controller and action, so there is no controllrt/action in the url to allow ZF to work out where it is.)</p> <p><strong>Update:</strong> Ahem.... Seems like the code I suggested did actually work, and can actually be done slightly more simply using the magic finder methods...:</p> <pre><code> $nav-&gt;findOneById($currentPageId)-&gt;setActive(true); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload