public function notFoundAction()
    {
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');

        // I create a template path in which I can find a custom template
        $controller     = explode('\\', get_class($this));
        $controllerPath = str_replace('Controller', '', end($controller));
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
        $uri            = $this->getRequest()->getUri()->getPath();
        if ($this->game) {
            $uri = str_replace($controllerPath.'/'.$this->game->getIdentifier().'/', '', $uri);
        }
        $uri      = str_replace("/".$this->getEvent()->getRouteMatch()->getParam('locale')."/", "/", $uri);
        $template = 'playground-game/'.$controllerPath.'/custom'.$uri;

        $template = (substr($template, -strlen('.html')) === '.html') ? $template : $template . '.phtml';
        if (false === $templatePathResolver->resolve($template)) {
            $viewRender = $this->getServiceLocator()->get('ViewRenderer');

            $this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
            $this->response->setStatusCode(404);

            $res = 'error/404';

            $viewModel = $this->buildView($this->game);
            $viewModel->setTemplate($res);

            $this->layout()->setVariable("content", $viewRender->render($viewModel));
            $this->response->setContent($viewRender->render($this->layout()));

            return $this->response;
        }

        $viewModel = $this->buildView($this->game);
        $viewModel->setTemplate($template);

        return $viewModel;
    }
public function notFoundAction()
    {
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');

        // I create a template path in which I can find a custom template
        $controller     = explode('\\', get_class($this));
        $controllerPath = str_replace('Controller', '', end($controller));
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
        $uri            = $this->getRequest()->getUri()->getPath();
        if ($this->game) {
            $uri = str_replace($controllerPath.'/'.$this->game->getIdentifier().'/', '', $uri);
        }
        $uri      = str_replace("/".$this->getEvent()->getRouteMatch()->getParam('locale')."/", "/", $uri);
        $template = 'playground-game/'.$controllerPath.'/custom'.$uri;

        $template = (substr($template, -strlen('.html')) === '.html') ? $template : $template . '.phtml';
        if (false === $templatePathResolver->resolve($template)) {
            $viewRender = $this->getServiceLocator()->get('ViewRenderer');

            $this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
            $this->response->setStatusCode(404);

            $res = 'error/404';

            $viewModel = $this->buildView($this->game);
            $viewModel->setTemplate($res);

            $this->layout()->setVariable("content", $viewRender->render($viewModel));
            $this->response->setContent($viewRender->render($this->layout()));

            return $this->response;
        }

        $viewModel = $this->buildView($this->game);
        $viewModel->setTemplate($template);

        return $viewModel;
    }
public function notFoundAction ( ) { $ templatePathResolver = $ this -> getServiceLocator ( ) -> get ( 'Zend\View\Resolver\TemplatePathStack' ) ; // I create a template path in which I can find a custom template $ controller = explode ( '\\' , get_class ( $ this ) ) ; $ controllerPath = str_replace ( 'Controller' , '' , end ( $ controller ) ) ; $ controllerPath = strtolower ( preg_replace ( '/(?<=\\w)([A-Z])/' , '-\\1' , $ controllerPath ) ) ; $ uri = $ this -> getRequest ( ) -> getUri ( ) -> getPath ( ) ; if ( $ this -> game ) { $ uri = str_replace ( $ controllerPath . '/' . $ this -> game -> getIdentifier ( ) . '/' , '' , $ uri ) ; } $ uri = str_replace ( "/" . $ this -> getEvent ( ) -> getRouteMatch ( ) -> getParam ( 'locale' ) . "/" , "/" , $ uri ) ; $ template = 'playground-game/' . $ controllerPath . '/custom' . $ uri ; $ template = ( substr ( $ template , - strlen ( '.html' ) ) === '.html' ) ? $ template : $ template . '.phtml' ; if ( false === $ templatePathResolver -> resolve ( $ template ) ) { $ viewRender = $ this -> getServiceLocator ( ) -> get ( 'ViewRenderer' ) ; $ this -> getEvent ( ) -> getRouteMatch ( ) -> setParam ( 'action' , 'not-found' ) ; $ this -> response -> setStatusCode ( 404 ) ; $ res = 'error/404' ; $ viewModel = $ this -> buildView ( $ this -> game ) ; $ viewModel -> setTemplate ( $ res ) ; $ this -> layout ( ) -> setVariable ( "content" , $ viewRender -> render ( $ viewModel ) ) ; $ this -> response -> setContent ( $ viewRender -> render ( $ this -> layout ( ) ) ) ; return $ this -> response ; } $ viewModel = $ this -> buildView ( $ this -> game ) ; $ viewModel -> setTemplate ( $ template ) ; return $ viewModel ; }
Action called if matched action does not exist
For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
it has to be rendered in the controller. Hence the code below.

This action is injected as a catchall action for each custom_games definition
This way, when a custom_game is created, the 404 is it's responsability and the
view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml


@return \Zend\Stdlib\ResponseInterface
Action called if matched action does not exist For this view not to be catched by Zend \ Mvc \ View \ RouteNotFoundStrategy it has to be rendered in the controller . Hence the code below .