I'm new to ZF2 and bjyauthorize - so in a way hoping this is a silly mistake on my part :D
I have setup the ZF2 skeleton app and zfcUser successfully and am trying to add bjyAuthorize to the mix. I am also using the Zend/Db connection type to mySQL - NOT DOCTRINE (:D). The versions I am using are PHP(5.5), ZF2(2.3.*), zfcUser(1.2.1), bjyAuthorize(1.4.0).
I have followed the instructions found to the letter in the GitHub Readme. It didn't take me long to realise that the example "bjyauthorize.global.php" file there contains way too many settings (as examples) and also has an incorrect field reference under "\BjyAuthorize\Provider\Role\ZendDb::class" ("role_id" s/b "roleid").
Basically, as soon as I uncomment either the route based or controller based guards in my config file (i don't intend to do both - just want one working) I get a white screen - no error message to be helpful - when trying to access my skeleton apps home page. I'm worried this is therefore a PHP syntax error on my part.
I have also included ZendDeveloperTools and not even the tool bar on the footer appears when I get this error.
Here is my config file:
<?php
return [
'bjyauthorize' => [
// set the 'guest' role as default (must be defined in a role provider)
'default_role' => 'guest',
/* this module uses a meta-role that inherits from any roles that should
* be applied to the active user. the identity provider tells us which
* roles the "identity role" should inherit from.
*
* for ZfcUser, this will be your default identity provider
*/
'identity_provider' => \BjyAuthorize\Provider\Identity\ZfcUserZendDb::class,
/* role providers simply provide a list of roles that should be inserted
* into the Zend\Acl instance. the module comes with two providers, one
* to specify roles in a config file and one to load roles using a
* Zend\Db adapter.
*/
'role_providers' => [
// this will load roles from the user_role table in a database
// format: user_role(role_id(varchar], parent(varchar))
\BjyAuthorize\Provider\Role\ZendDb::class => [
'table' => 'user_role',
'identifier_field_name' => 'id',
'role_id_field' => 'roleid',
'parent_role_field' => 'parent_id',
],
],
/* Currently, only controller and route guards exist
*
* Consider enabling either the controller or the route guard depending on your needs.
*/
'guards' => [
/* If this guard is specified here (i.e. it is enabled], it will block
* access to all controllers and actions unless they are specified here.
* You may omit the 'action' index to allow access to the entire controller
*/
// \BjyAuthorize\Guard\Controller::class => [
// ['controller' => 'zfcuser', 'roles' => ['guest']],
// ['controller' => ['Application\Controller\Index'], 'roles' => ['guest']],
// ],
// /* If this guard is specified here (i.e. it is enabled], it will block
// * access to all routes unless they are specified here.
// */
// \BjyAuthorize\Guard\Route::class => [
// ['route' => 'zfcuser', 'roles' => ['user']],
// ['route' => 'zfcuser/logout', 'roles' => ['user']],
// ['route' => 'zfcuser/login', 'roles' => ['guest']],
// ['route' => 'zfcuser/register', 'roles' => ['guest']],
// // Below is the default index action used by the ZendSkeletonApplication
// ['route' => 'home', 'roles' => ['guest', 'user']],
// ],
],
],
];
When I run as coded above without guards, I can login through site/user/login and the Zend Dev ToolBar shows me the correct role for that user. So that is at least positive.
Happy to provide any further info or settings - just trying to learn.
OK, so I feel quite silly now.
The DB schema that bjyauthorize ships with has the field "roleId" - in my code above I didn't take into account case sensitivity and had "roleid". Changed that and everything works perfectly.