-
-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using forward/dispatch results in different RouteMatch class object #27
Comments
I'm experiencing somewhat similar issue. My Listener code is below public function userHasAuthentication(MvcEvent $e)
{
$routeMatch = $e->getApplication()
->getServiceManager()
->get("HttpRouter")
->match($e->getRequest());
if ($routeMatch) {
$controllerName = explode("\\", $routeMatch->getParam("controller"))[2];
$actionName = $routeMatch->getParam("action");
$actionName = str_replace("-", "", lcfirst(ucwords($actionName, "-")));
$moduleName = explode("\\", $routeMatch->getParam("controller"))[0];
if ($controllerName !== "UserController"
&& $actionName !== "login"
&& $actionName !== "logout"
) {
$result = $this->getLoginService()
->filterAccess($moduleName, $controllerName, $actionName, $taskName = "*");
if ($result == LoginService::AUTH_REQUIRED) {
$routeMatch->setParam("controller", UserController::class);
$routeMatch->setParam("action", "login");
}
if ($result == LoginService::ACCESS_DENIED) {
$routeMatch->setParam("controller", UserController::class);
$routeMatch->setParam("action", "unauthorized");
$e->getResponse()
->setStatusCode(401);
}
}
}
} //Router code
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'dashboard' => [
'type' => Literal::class,
'options' => [
'route' => '/dashboard',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'dashboard',
],
],
],
Module::ROUTE_NAME_MODULE => [ // user
"type" => Segment::class,
"options" => [
"route" => Module::ROUTE_PREFIX,
"defaults" => [
"controller" => UserController::class,
"action" => "index",
],
],
"may_terminate" => true,
"child_routes" => [
Module::ROUTE_NAME_ACTIONS => [ //actions ===> results in user/actions
"type" => Segment::class,
"options" => [
"route" => "/:action[/:id]",
"constraints" => [
"action" => "[a-zA-Z][a-zA-Z0-9_-]*",
"id" => "[0-9]+",
],
],
],
],
], All works as per the code except below.
This is always If I use the below code $routeMatch->setMatchedRouteName(
"user/actions"
); It keeps suffixing it to original matchedRouteName i.e. dashboard which sometimes becomes something like
P.S. I don't want to use Thanks. |
@goharsahi |
This issue has been moved from the
zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.htmlOriginal Issue: https://api.github.com/repos/zendframework/zendframework/issues/7389
User: @kuldeep-k
Created On: 2015-03-31T08:32:24Z
Updated At: 2015-11-06T21:05:11Z
Body
I am building a rest based auth forwarding. So I do code like below in listener class
So first time request comes for controller Rest\Controller\Index action index (matched route "rest") but due to authentication failure forward happens to controller Rest\Controller\Error action auth (matched route "rest-error")
However what is printed is below
Which show that first request go to Zend\Mvc\Router\Http\RouteMatch while subsequent request goes to Zend\Mvc\Router\RouteMatch ( Due to not check of safe route request recursively goes end throw expected error "Circular forwarding detected")
Now from second request do not have controller information also, It matched to wrong matchedRouteName.
module.config.php have these routes
I tried on Zend Framework v2.3.4 & v2.2.4 .
Originally posted by @GeeH at zendframework/zend-mvc#174
The text was updated successfully, but these errors were encountered: