Question

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?

Was it helpful?

Solution

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',
),

OTHER TIPS

You can manually set:

'error/403' => __DIR__ . '/../view/error/403.phtml',

in module/Application/config/module.config.php and comment out this line in module.bjyauthorize.global.php. I'm assuming you are working with the skeleton.

@aravind.udayashankara, BjyAuthorize does work with composer and the skeleton already comes configured to load modules in the vendor as well, so no need to move it in modules directory.

However, it does seem that phprender isn't able to access the view directory in the vendor. It might be the way "error/403' => DIR . '/../view/error/403.phtml" is actually mapped/interpreted at runtime.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top