By default, the page is set this way in the Application module.config array:
'template_map' => array( 'error/404' => __DIR__ . '/../view/error/404.phtml'
I want to change the page. I want a new ViewModel for it full of variables. This means that simply changing the template is not enough:
'error/404' => __DIR__ . '/../view/error/my_new_404_template.phtml'
But I can’t figure out how to do this. I do not see how the request comes in 'error/404' .
How to create a new ViewModel for it?
How to connect variables to it?
How does a route reach 'error/404' to intercept it?
For example, I have a method for the 'error/404' page:
public function pageNotFoundAction() { $view = new ViewModel(); $view->setTemplate('error/404'); // set my template $sm = $this->getServiceLocator()->get('SessionManager'); $cont = new Container('SomeNamespace', $sm); $view->var1 = $cont->offsetGet('someValue1'); // the "error/404" template $view->var2 = $cont->offsetGet('someValue2'); // is full of variables $view->var3 = $cont->offsetGet('someValue3'); $view->var4 = "One more view variable"; // And now I return it somewhere and want it to be called // in case of "the page is not found" return $view; }
How to make such a change? I can’t get the system they created to deal with things like 'error/404' . Please, help.
UPD 1
An even more difficult task. How to have multiple 'error/404' pages? I would like to ask the guys who created the framework if they know that 'not_found_template' cannot have an array of pages 'error/404' . How can it be? If I set this parameter as follows:
'template_map' => array( 'error/404' => __DIR__ . '/../view/error/404.phtml', 'my-page/one_more_error404' => __DIR__ . '/../view/my-page/my-page/one_more_error404.phtml', 'other_page/second_404' => __DIR__ . '/../view/other-page/one_more_error404.phtml', 'not_found_template' => array( 'error/404', 'my-page/one_more_error404', 'other-page/second_404', );
he gives an error. 'not_found_template' forces you to have only one 'error/404' template?