I just setup the bjyoungblood/bjy-authorize
and wonder how I can tell Zend Framework 2 where my error/403
template lies.
I didn't configure the initial setting of 'template' => 'error/403',
The 403.phtml
file lies within the vendor directory but I get the following error message:
Warning: include(C:\myproject\config\autoload/../view/error/403.phtml) [function.include]: failed to open stream: No such file or directory in C:\myproject\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php on line 507
What is wrong with my configuration?
For performance reasons (mainly avoiding stat calls), BjyAuthorize uses the template map to define which file to use when the error/403
view is requested. This is an option of the view_manager
settings, as described in the Zend\View
documentation.
To set your own, you can simply define something like following in your config/autoload/your-settings.local.php
:
'view_manager' => array(
'template_map' => array(
'error/403' => '/absolute/path/to/your/error/403.phtml',
),
),
Or, in your module config:
'view_manager' => array(
'template_map' => array(
'error/403' => __DIR__ . '/view/error/403.phtml',
),
),
I suggest always providing absolute paths for configuration, so be sure that your file C:\myproject\config\autoload/../view/error/403.phtml
is the correct path.
You can also use a different view for 403 errors if you prefer to do so. That can be achieved by changing $config['bjyauthorize']['template']
:
'bjyauthorize' => array(
'template' => 'my-module/unauthorized-template',
),