在 module.php 中确定 zend framework3 中的控制器、操作、路由名称
to determine the controller, action , route name in zend framework3 in module.php
我试图在 ZF3 中获取匹配的路由名称和控制器 - 操作名称
我想要 Module.php、
我已经试过了-
public function onBootstrap(MvcEvent $e)
{
$app = $e->getApplication();
$em = $app->getEventManager()->getSharedManager();
$sm = $app->getServiceManager();
$routeMatch = $sm->get('Application')->getMvcEvent()->getRouteMatch();
}
但是 returns null
,
提前致谢
试试这个-
public function onBootstrap(MvcEvent $e)
{
$app = $e->getApplication();
$em = $app->getEventManager()->getSharedManager();
$sm = $app->getServiceManager();
$app->getEventManager()->attach( MvcEvent::EVENT_DISPATCH, function ($e) use ($sm){
$routeMatch = $sm->get('Application')->getMvcEvent()->getRouteMatch();
var_dump($routeMatch->getParams());
var_dump($routeMatch->getMatchedRouteName());exit;
}, 200);
}
On bootstrap (function onBootstrap),路由还没有准备好,所以需要在一些事件上获取路由,
例如:(EVENT_DISPATCH, EVENT_RENDER, EVENT_ROUTE)
我试图在 ZF3 中获取匹配的路由名称和控制器 - 操作名称 我想要 Module.php、
我已经试过了-
public function onBootstrap(MvcEvent $e)
{
$app = $e->getApplication();
$em = $app->getEventManager()->getSharedManager();
$sm = $app->getServiceManager();
$routeMatch = $sm->get('Application')->getMvcEvent()->getRouteMatch();
}
但是 returns null
,
提前致谢
试试这个-
public function onBootstrap(MvcEvent $e)
{
$app = $e->getApplication();
$em = $app->getEventManager()->getSharedManager();
$sm = $app->getServiceManager();
$app->getEventManager()->attach( MvcEvent::EVENT_DISPATCH, function ($e) use ($sm){
$routeMatch = $sm->get('Application')->getMvcEvent()->getRouteMatch();
var_dump($routeMatch->getParams());
var_dump($routeMatch->getMatchedRouteName());exit;
}, 200);
}
On bootstrap (function onBootstrap),路由还没有准备好,所以需要在一些事件上获取路由,
例如:(EVENT_DISPATCH, EVENT_RENDER, EVENT_ROUTE)