Op Monday 22 June 2009 08:02:26 schreef Marko Korhonen:
> Hi,
>
> I tried the Zend_Navigation in my project and I bumped into following
> challenges:
>
> 1. How can I add subpages dynamically so I don't have to declare all my
> pages in ini, xml or array?
>
> Example:
>
> I have main level: home, projects, users
> second level for projects would be projects > project ID 3
>
> So, how could I add this project ID 3 page under projects page (which is
> defined in INI file).
>
> Now I made "dummy" subpage to my ini file, which I just update dynamically
> with correct label and url.
>
You could add dynamically your subpages. I do the same for my blog articles
and portfolio projects. You can do something like this:
Zend_Registry::get('Zend_Navigation')->findBy('url', $url)-
>addPages($subPages);
Because for your view helper, Zend_Navigation should already exists in the
registry. The url depends on where your are of course. I assemble the path
with the router. In my action controller:
$url = $this->getFrontController->getRouter()->assemble(array(
'property-1' => 'default-value-1',
'property-2' => 'default-value-2'
));
> 2. Do I need to set my home page active by default?
>
> Now breadcrumbs() helper shows some weird breadcrumb on my homepage.
> Apparently active page is the way Zend_Navigation creates the breadcrumb
> and not some Url detection?
>
> In subpages the breadcrumbs work correctly if I set the active page
> manually.
>
You should always set a page to active, it cannot determine it automatically.
Because the breadcrumbs tries to find the deepest active page, it might be an
idea to set your homepage (at top level I guess) active by default. If no
active page is found, the breadcrumbs will show your homepage for sure.
> br, Marko
--
Jurian Sluiman
Soflomo.com