ZF2: How to get Zend\Navigation inside custom router?
Posted
by
Katan87
on Stack Overflow
See other posts from Stack Overflow
or by Katan87
Published on 2012-11-10T16:56:47Z
Indexed on
2012/11/10
16:59 UTC
Read the original article
Hit count: 340
I have custom router and I have to get access to Zend\Navigation
inside this custom router. I was googling, asking and searching and no results :/
All I need is to find nodes with 'link' param using Zend\Navigation in my AliasSegment::match function.
Here is my module.config.php:
'navigation' => array(
// The DefaultNavigationFactory we configured in (1) uses 'default' as the sitemap key
'default' => array(
// And finally, here is where we define our page hierarchy
'account' => array(
'label' => 'Account',
'route' => 'node',
'pages' => array(
'home' => array(
'label' => 'Dashboard',
'route' => 'node',
'params' => array(
'id' => '1',
'link' => '/about/gallery'
),
),
'login' => array(
'label' => 'Sign In',
'route' => 'node',
'params' => array(
'id' => '1',
'link' => '/signin'
),
),
'logout' => array(
'label' => 'Sign Out',
'route' => 'node',
),
),
),
),
),
[...]
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'Navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
),
),
[...]
And here is my AliasSegment class:
namespace Application\Controller;
use Traversable;
use Zend\Mvc\Router\Exception;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\RequestInterface as Request;
use Zend\Mvc\Router\Http;
class AliasSegment extends \Zend\Mvc\Router\Http\Segment
{
public function match(Request $request, $pathOffset = null)
{
//Here i need to have access to Zend\Navigation
return parent::match($request, $pathOffset);
}
}
© Stack Overflow or respective owner