Ответ 1
Вы можете настроить диспетчер для этого.
Когда вы загружаете приложение, вы можете это сделать ($di
- ваш DI factory):
use \Phalcon\Mvc\Dispatcher as PhDispatcher;
$di->set(
'dispatcher',
function() use ($di) {
$evManager = $di->getShared('eventsManager');
$evManager->attach(
"dispatch:beforeException",
function($event, $dispatcher, $exception)
{
switch ($exception->getCode()) {
case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(
array(
'controller' => 'error',
'action' => 'show404',
)
);
return false;
}
}
);
$dispatcher = new PhDispatcher();
$dispatcher->setEventsManager($evManager);
return $dispatcher;
},
true
);
Создайте ErrorController
<?php
/**
* ErrorController
*/
class ErrorController extends \Phalcon\Mvc\Controller
{
public function show404Action()
{
$this->response->setStatusCode(404, 'Not Found');
$this->view->pick('404/404');
}
}
и вид 404 (/views/404/404.volt
)
<div align="center" id="fourohfour">
<div class="sub-content">
<strong>ERROR 404</strong>
<br />
<br />
You have tried to access a page which does not exist or has been moved.
<br />
<br />
Please click the links at the top navigation bar to
navigate to other parts of the site, or
if you wish to contact us, there is information in the About page.
<br />
<br />
[ERROR]
</div>
</div>