Я хотел бы создать шаблон ошибки 403 Forbidden и отобразить его с контроллера.
В моем module.config.php у меня есть следующая запись.
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'forbidden_template' => 'error/403',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/403' => __DIR__ . '/../view/error/403.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
Как видите, я добавил шаблон 403 и файл 403.phtml в папку просмотра/ошибки.
В моем контроллере я пробовал.
$response = $this->getResponse();
$response->setStatusCode(403);
Но ничего не происходит, отображается страница по умолчанию. Когда я изменяю 403 на 404 в приведенном выше коде, отображается страница ошибки 404.
Пожалуйста, может кто-нибудь сказать мне, что мне не хватает, большое спасибо.