-
Notifications
You must be signed in to change notification settings - Fork 25
Zend\Navigation does not work with Zend\Expressive #56
Comments
I also found out, that |
Right. At the moment, the navigation component supports the old router of the mvc component and the new router component: use Zend\Mvc\Router as MvcRouter;
use Zend\Router\RouteMatch;
use Zend\Router\RouteStackInterface; But I think this is not the problem. Please have a look at $application = $container->get('Application');
$routeMatch = $application->getMvcEvent()->getRouteMatch();
$router = $application->getMvcEvent()->getRouter();
$request = $application->getMvcEvent()->getRequest(); This matches the error message you posted. And this is the problem!
Sure! 😃
|
Yep. Currently To split this up we might need some integration components for |
Right, but only in the current factories!
Yes and no! 😉 |
Nope :) I really tried to find a better way but for now thats what works for me. At least with the Page\Mvc. /**
* @param ContainerInterface $container
* @param array|\Zend\Config\Config $pages
* @return null|array
* @throws \Zend\Navigation\Exception\InvalidArgumentException
*/
protected function preparePages(ContainerInterface $container, $pages)
{
/** @var RouterInterface $router */
$router = $container->get(RouterInterface::class);
// mah... it's ugly, i know
$request = ServerRequestFactory::fromGlobals();
$routeMatch = $router->match($request);
// HTTP request is the only one that may be injected
if (! $request instanceof Request) {
$request = null;
}
return $this->injectComponents($pages, $routeMatch, $router, $request);
} |
Please read carefully, because the content of Ralf's message was different:
The same here: the mvc component is not needed.
Right, but that was not the content of Ralf's message. $routeMatch = $router->match($request); This creates a |
And yep, the match method will create a Didn't expect that zend-expressive have own implementation for the routing. I supposed zend-expressive uses zend-router. |
We developed an abstraction around routing, to allow usage of any routing library, and provide three implementations: Aura.Route, FastRoute, and zend-router; FastRoute is the recommended router! Thanks for opening this issue; clearly, we need to see if we can make it a bit more generic going forward! |
When you plan to fix the bug? I need to understand whether or not to wait for the decision or to use something else for menu. |
This is not a bug, because When? I will look into over the weekend. |
@froschdesign that will be really great! |
@RalfEggert and @weierophinney I wanted an implementation for version 2 of (Notice: at the moment there is no support for multiple navigations) Usagedependencies.global.php 'dependencies' => [
'factories' => [
Zend\Navigation\Navigation::class => Zend\Navigation\Service\ExpressiveNavigationFactory::class,
],
'delegators' => [
Zend\View\HelperPluginManager::class => [
Zend\Navigation\View\ViewHelperManagerDelegatorFactory::class,
],
],
], middleware-pipeline.global.php 'dependencies' => [
'factories' => [
Zend\Navigation\Middleware\NavigationMiddleware::class => Zend\Navigation\Middleware\NavigationMiddlewareFactory::class,
],
],
'middleware_pipeline' => [
'routing' => [
'middleware' => [
ApplicationFactory::ROUTING_MIDDLEWARE,
Zend\Navigation\Middleware\NavigationMiddleware::class,
ApplicationFactory::DISPATCH_MIDDLEWARE,
],
],
], Add a configuration for the navigation itself: navigation.global.php return [
'navigation' => [
'default' => [
[
'label' => 'Home',
'route' => 'home',
],
[
'label' => 'Add album',
'route' => 'album',
'params' => [
'action' => 'add',
],
],
[
'label' => 'Edit album',
'route' => 'album',
'params' => [
'action' => 'edit',
],
],
],
],
]; |
This looks great. Having an additional In the long run we should make 👍 👍 👍 |
Maybe this move can one time address performance issues that are turning people away from it (or at least I have seen in IRC complain, not sure exactly why, I suspect it deals with redundant router match). If navigation is told what is active, instead of the other way around, have opportunity to do better tree traversing, instead of brute-force recursive check of all nodes. If Z\Navigation stores its page node references not purely based on navigation hierarchy, but is "indexed" but route property of the pages, that index can be taken advantage of to quickly mark what page is active with $navigation->setActive($routerPath). |
Any news? I am really looking forward for this patch to let |
@RalfEggert The support for multiple navigations is still missing. |
@froschdesign thankyou for you patch |
@froschdesign |
NewsCode updates
(not yet online - sorry!) Next steps
WhenI hope tomorrow! |
Nice one! 👍 |
It just comes in time with |
@unnamed666 Please open a new issue with your question, instead of commenting on an unrelated one. Alternately, use our new forums: https://discourse.zendframework.com. |
I wanted to create a new project based on Expressive and had the same errors as Ralf and saw that there is a pull request, which is still open. Could you tell us, when it will be possible to use zend-navigation in Expressive or what I could do to use it with the current version (if possible)? In the documentation of Expressive the navigation isn't mentioned. |
Right, because this feature is still work in progress. You can use this branch for testing: https://github.com/froschdesign/zend-navigation/tree/feature/expressive-support After testing, please come back and give us a feedback. Thanks! |
@froschdesign Thank you for your fast reply. I configured the files described. When using a single navigation, the output is working fine and the active menu item is getting his "active" class. But I wasn't able to use a second navigation, even after adding the abstract_factory to the dependencies. I'm getting the error message
Is there something wrong with my config or is the support of multiple containers missing in that branch? |
I see nothing! 😉
No. ( |
First I used the config for the single container and with the 'default' block in my navigation config. In the second step I extended my dependencies.global.php and added a second block in my navigation config.
My (complete) dependencies.global.php return [
'dependencies' => [
'abstract_factories' => [
Zend\Navigation\Service\ExpressiveNavigationAbstractServiceFactory::class,
],
'aliases' => [
'Zend\Expressive\Delegate\DefaultDelegate' => Zend\Expressive\Delegate\NotFoundDelegate::class,
],
'delegators' => [
Zend\View\HelperPluginManager::class => [
Zend\Navigation\View\ViewHelperManagerDelegatorFactory::class,
],
],
'invokables' => [
Zend\Expressive\Helper\ServerUrlHelper::class => Zend\Expressive\Helper\ServerUrlHelper::class,
Zend\Expressive\Router\RouterInterface::class => Zend\Expressive\Router\ZendRouter::class,
],
'factories' => [
'doctrine.entity_manager.orm_default' =>
ContainerInteropDoctrine\EntityManagerFactory::class,
Zend\Navigation\Navigation::class =>
Zend\Navigation\Service\ExpressiveNavigationFactory::class,
Zend\Expressive\Application::class =>
Zend\Expressive\Container\ApplicationFactory::class,
Zend\View\HelperPluginManager::class =>
Zend\Expressive\ZendView\HelperPluginManagerFactory::class,
Zend\Expressive\Template\TemplateRendererInterface::class =>
Zend\Expressive\ZendView\ZendViewRendererFactory::class,
Zend\Expressive\Delegate\NotFoundDelegate::class =>
Zend\Expressive\Container\NotFoundDelegateFactory::class,
Zend\Expressive\Helper\ServerUrlMiddleware::class =>
Zend\Expressive\Helper\ServerUrlMiddlewareFactory::class,
Zend\Expressive\Helper\UrlHelper::class =>
Zend\Expressive\Helper\UrlHelperFactory::class,
Zend\Stratigility\Middleware\ErrorHandler::class =>
Zend\Expressive\Container\ErrorHandlerFactory::class,
Zend\Expressive\Middleware\ErrorResponseGenerator::class =>
Zend\Expressive\Container\ErrorResponseGeneratorFactory::class,
Zend\Expressive\Middleware\NotFoundHandler::class =>
Zend\Expressive\Container\NotFoundHandlerFactory::class,
],
],
]; My complete middleware-pipeline.global.php return [
'dependencies' => [
'factories' => [
Zend\Navigation\Middleware\NavigationMiddleware::class =>
Zend\Navigation\Middleware\NavigationMiddlewareFactory::class,
Zend\Expressive\Helper\UrlHelperMiddleware::class =>
Zend\Expressive\Helper\UrlHelperMiddlewareFactory::class,
],
],
'middleware_pipeline' => [
'always' => [
'middleware' => [
Zend\Expressive\Helper\ServerUrlMiddleware::class,
],
'priority' => 10000,
],
'routing' => [
'middleware' => [
Zend\Expressive\Container\ApplicationFactory::ROUTING_MIDDLEWARE,
Zend\Navigation\Middleware\NavigationMiddleware::class,
Zend\Expressive\Helper\UrlHelperMiddleware::class,
Zend\Expressive\Container\ApplicationFactory::DISPATCH_MIDDLEWARE,
],
'priority' => 1,
],
'error' => [
'middleware' => [
// Add error middleware here.
],
'error' => true,
'priority' => -10000,
],
], My navigation block inside the config of my module: 'navigation' => [
'default' => [
[
'label' => 'Startseite',
'route' => 'home',
],
],
'footer' => [
[
'label' => 'Impressum',
'route' => 'imprint',
],
],
], |
@av3 |
@froschdesign
|
Why? Don't do this! |
Sorry, I misunderstood the instructions. But only removing the
Now I have the dependencies.global.php return [
'dependencies' => [
'aliases' => [
'Zend\Expressive\Delegate\DefaultDelegate' => Zend\Expressive\Delegate\NotFoundDelegate::class,
],
'abstract_factories' => [
Zend\Navigation\Service\ExpressiveNavigationAbstractServiceFactory::class,
],
'delegators' => [
Zend\View\HelperPluginManager::class => [
Zend\Navigation\View\ViewHelperManagerDelegatorFactory::class,
],
],
'invokables' => [
Zend\Expressive\Helper\ServerUrlHelper::class => Zend\Expressive\Helper\ServerUrlHelper::class,
],
'factories' => [
'doctrine.entity_manager.orm_default' =>
ContainerInteropDoctrine\EntityManagerFactory::class,
Zend\Expressive\Router\RouterInterface::class =>
Zend\Expressive\Router\FastRouteRouterFactory::class,
Zend\Expressive\Application::class =>
Zend\Expressive\Container\ApplicationFactory::class,
Zend\View\HelperPluginManager::class =>
Zend\Expressive\ZendView\HelperPluginManagerFactory::class,
Zend\Expressive\Template\TemplateRendererInterface::class =>
Zend\Expressive\ZendView\ZendViewRendererFactory::class,
Zend\Expressive\Delegate\NotFoundDelegate::class =>
Zend\Expressive\Container\NotFoundDelegateFactory::class,
Zend\Expressive\Helper\ServerUrlMiddleware::class =>
Zend\Expressive\Helper\ServerUrlMiddlewareFactory::class,
Zend\Expressive\Helper\UrlHelper::class =>
Zend\Expressive\Helper\UrlHelperFactory::class,
Zend\Expressive\Helper\UrlHelperMiddleware::class =>
Zend\Expressive\Helper\UrlHelperMiddlewareFactory::class,
Zend\Stratigility\Middleware\ErrorHandler::class =>
Zend\Expressive\Container\ErrorHandlerFactory::class,
Zend\Expressive\Middleware\ErrorResponseGenerator::class =>
Zend\Expressive\Container\ErrorResponseGeneratorFactory::class,
Zend\Expressive\Middleware\NotFoundHandler::class =>
Zend\Expressive\Container\NotFoundHandlerFactory::class,
],
],
]; middleware_pipeline.global.php return [
'dependencies' => [
'factories' => [
Zend\Navigation\Middleware\NavigationMiddleware::class =>
Zend\Navigation\Middleware\NavigationMiddlewareFactory::class,
Zend\Expressive\Helper\UrlHelperMiddleware::class =>
Zend\Expressive\Helper\UrlHelperMiddlewareFactory::class,
],
],
'middleware_pipeline' => [
'always' => [
'middleware' => [
Zend\Expressive\Helper\ServerUrlMiddleware::class,
],
'priority' => 10000,
],
'routing' => [
'middleware' => [
Zend\Expressive\Container\ApplicationFactory::ROUTING_MIDDLEWARE,
Zend\Navigation\Middleware\NavigationMiddleware::class,
Zend\Expressive\Helper\UrlHelperMiddleware::class,
Zend\Expressive\Container\ApplicationFactory::DISPATCH_MIDDLEWARE,
],
'priority' => 1,
],
'error' => [
'middleware' => [
// Add error middleware here.
],
'error' => true,
'priority' => -10000,
],
],
]; |
Firstly, thanks @froschdesign for your work on feature/expressive-support. From navigating (no pun intended) through the code today I have learned that there is much more to this component than I realised. @av3 I apologise if my comments are not helpful in your circumstances, but I observed the same error message that you described so I thought I would add my experience today in case it was helpful to you. I was trying to use multiple navigation containers, but after I added the abstract factory
Looking back at the suggested usage it seems pretty obvious to me now, but it took me some time to figure it out. My mistake was to include Abstract factories appear to be processed in the order they are added. In my case the first to execute was the original To work around this it is possible to explicitly map each navigation service to the correct abstract factory, ensuring that 'factories' => [
'Zend\\Navigation\\One' =>
Zend\Navigation\Service\ExpressiveNavigationAbstractServiceFactory::class,
'Zend\\Navigation\\Two' =>
Zend\Navigation\Service\ExpressiveNavigationAbstractServiceFactory::class,
'Zend\\Navigation\\Three' =>
Zend\Navigation\Service\ExpressiveNavigationAbstractServiceFactory::class,
], For me, the simplest solution was to not include This is the only additional configuration I needed to get it working: 'dependencies' => [
'abstract_factories' => [
Zend\Navigation\Service\ExpressiveNavigationAbstractServiceFactory::class,
],
'delegators' => [
Zend\View\HelperPluginManager::class => [
Zend\Navigation\View
],
],
'factories' => [
Zend\Navigation\Middleware\NavigationMiddleware::class =>
Zend\Navigation\Middleware\NavigationMiddlewareFactory::class,
],
], I also used the programmatic approach, so adding $app->pipeRoutingMiddleware();
// ...
$app->pipe(\Zend\Navigation\Middleware\NavigationMiddleware::class);
// ...
$app->pipeDispatchMiddleware(); |
Right, because at the moment the /cc @av3 |
Is there a plan when milestone 2.9 will be released? |
This repository has been closed and moved to laminas/laminas-navigation; a new issue has been opened at laminas/laminas-navigation#2. |
I want to use
Zend\Navigation
in aZend\Expressive
application. First of all, I installed it:Composer installed it and added the
ConfigProvider
to my/config/config.php
file:When I try to use the navigation view helper in a template, I get this error:
So, I added the
Zend\Navigation\View\ViewHelperManagerDelegatorFactory
to my configuration:No I get this error:
After some investigation the problem is located here:
https://github.com/zendframework/zend-navigation/blob/master/src/Service/AbstractNavigationFactory.php#L102
The
AbstractNavigationFactory
seems to have a hard dependency on the MVC application which makes it impossible to useZend\Navigation
withZend\Expressive
currently.Are there any plans to solve this? What should be done to break up this hard dependency? I guess it would be quite complicated to run
Zend\Navigation
both withZend\Mvc
andZend\Expressive
, wouldn't it?The text was updated successfully, but these errors were encountered: