开发者

Setting active page when Zend_Navigation is cached?

开发者 https://www.devze.com 2023-03-20 19:07 出处:网络
Update - Please see update below. I\'m attempting to improve the performance of our ZF based CMS, and am trying out caching the Zend_Navigation object I create with the menu structure.Caching the obj

Update - Please see update below.

I'm attempting to improve the performance of our ZF based CMS, and am trying out caching the Zend_Navigation 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.

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 Breadcrumb_Helper (which uses the same Zend_Navigation object as the menu) wasn't displaying anything - obviously because I haven't got a page set to active.

Given I know the id of the page, is there a way to get inside the Zend_Navigation object to set that particular one to active?

Ideally I'd like to do something like:

        $nav->findOneBy("id", $currentPageId)->setActive(true);

But there doesn't seem to be a way to access the pages in the object like this. Looking at the code, using findOneBy to get the current page, then removePage to remove it, then setting the collected one to active, and using addPage to put the collected, updated one back in might be an option, but rather convoluted.

The other option is just to cache the array I use to construct the Zend_Navigation object, which would be easier to set the current page to active, after getting the base array from the cache.

(I should point out that all the pages in the cms just have urls like /privacy, /about-us, 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.)

Update: Ahem.... Seems like the code I suggested did actually work, and can actually be done slightly more simply using the magic finder methods...:

        $nav->findOneById($currentPageId)->setActive(true);


As noted above, this does indeed work:

$nav->findOneById($currentPageId)->setActive(true);
0

精彩评论

暂无评论...
验证码 换一张
取 消