Controller forwarding/calling generate 404 Error

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Controller forwarding/calling generate 404 Error

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

        $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();
        $listener = $serviceManager->get('First\Service\AuthListener');
        $eventManager->getSharedManager()->attach('First', 'dispatch', $listener, 100);

NOTE : I asked same question at but no answers found there.