2

I have Zend Navigation object with Acl and Roles:

echo $this->navigation()->menu('navigation')
->setAcl($this->acl)
->setRole(($this->user ? 'user' : 'guest'))
->render();

and its work perfectly (hides some pages)

BUT

when i use custom partial:

echo $this->navigation()->menu('navigation')
->setAcl($this->acl)
->setRole(($this->user ? 'user' : 'guest'))
->setPartial('partial/twitterBootstrapNavHeadUl.phtml')
->render();

and this partial content

foreach ($this->container as $page)
    echo $this->navigation()->menu()->htmlify($page);

it pass to the partial $this->container with ALL pages (via acl setted as unaviable)

Maybe i should pass acl etc to partial

foreach ($this->container as $page)
    echo $this->navigation()->menu()->setAcl($this->acl)->setRole(($this->user ? 'user' : 'guest'))->htmlify($page); // ?????????????????????

but how to achieve it?

Is there something what I should do/know?

Tomek Kobyliński
  • 1,290
  • 14
  • 25

1 Answers1

10
foreach ($this->container as $page){
    if($this->navigation()->accept($page))
        echo $this->navigation()->menu()->htmlify($page);
}

Why? In a custom view you have to run the check on your own.

  • Wow. Thanks. I spent a lot of time on documentation and I couldn't find this anywhere. – Tomek Kobyliński Aug 19 '13 at 12:41
  • 1
    Will the answer is correct I could not get it working properly. After some digging and thinking, I used the Navigation::setDefaultAcl & Navigation::setDefaultRole to get it working. Hope it might help some one in the future – MKroeders Nov 17 '13 at 16:23
  • I used the setDefault methods too @Hendriq but still I had to check the acl manually as Aleksander posted. – webDEVILopers Jun 02 '14 at 11:07
  • 1
    That is true, you need to use both. Ie the check of Aleksander and the set default methods – MKroeders Jun 02 '14 at 11:26
  • 1
    Here is a short summary on the issue based on the #zf2 manual examples: http://blog.webdevilopers.net/?p=32 – webDEVILopers Jun 03 '14 at 14:19