I am implementing REST based token based authorization mechanism. Now what I
want if invalid token comes request call Error Controller & respective
action.

Now in AuthListener file I write code for forward/call to an different
controller/action if authentication failed. That is

    $result = $this->adapter->authenticate();

    if (!$result->isValid()) {

        $response = $event->getResponse();

        // Set some response content
        $response->setStatusCode(401);

        $routeMatch = $event->getRouteMatch();
        $routeMatch->setParam('controller', 'First\Controller\Error');
        $routeMatch->setParam('action', 'Auth');
    }

Now I am getting 404 error - "The requested controller was unable to
dispatch the request". First I think I do not added route for Error/Auth,
but then I verified it got 404 for all other controller/action too. All are
directly accessible through their respective route. But forwarding resulting
in 404 error. One important thing - I sending authentication request through
phpunit to make unit test cases.

Module.php  :

    public function onBootstrap(MvcEvent $e)
    {
        $eventManager        = $e->getApplication()->getEventManager();
        $serviceManager        = $e->getApplication()->getServiceManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);
        $listener = $serviceManager->get('First\Service\AuthListener');
       
$listener->setAdapter($serviceManager->get('Rest\Service\BasicAuthAdapter'));
        $eventManager->getSharedManager()->attach('First', 'dispatch',
$listener, 100);
    }

NOTE : I asked same question at
http://stackoverflow.com/questions/29277630/zf2-controller-forwarding-calling-generate-404-error
but no answers found there.



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Controller-forwarding-calling-generate-404-Error-tp4662506.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to