php - Zend Navigation: Where should I load the ACL 'Role' in a private application -


i working on 'private' application, must logged in @ all. gives me bit of issue loading role zend navigation. 'init'ing zend navigation in bootstrap; fine until added acl zend nav. issue want load 'userrole' auth storage, there not storage yet until user logs in, gets me 'trying property of non-object' warning @ login page. because before login, there nothing in auth's storage, auth->userrole 'nothing' because auth->getinstance()->getidentity()->??? empty, until user logs in , auth configured.

i'm not using zend nav @ login page, in fact have alternate layout login page (no nav @ all); 'if !$auth->hasidentity' (false) use login layout, show login page matter system-wide, said application private defaulting 'guest' role or seems 'dirty' approach, because once user logs in have reconfigure auth anyhow. don't seem right set generic auth identity please login page.

what getting @ is, place move 'init' of zend nav, or @ least move configure acl part? may move whole thing?

this have in bootstrap.php zend navigation:

protected function _initnavigation() {     $this->_logger->info('bootstrap ' . __method__);      $this->bootstrap('layout');     $layout = $this->getresource('layout');     $view = $layout->getview();     $config = new zend_config_xml(application_path . '/configs/navigation.xml', 'nav');     $container = new zend_navigation($config);     $acl = new application_model_acl_acl();     $role = zend_auth::getinstance()->getidentity()->userrole;     $view->navigation($container)->setacl($acl)->setrole($role); } 

it '$role = zend_auth::getinstance()->getidentity()->userrole' empty (or non-object) @ time bootstrap runs.

all of acl takes place either in controller (at action) or may take place in models @ point, although don't anticicpate web service or anything, maybe stay in controller, have flexibility because have acl in models (that 'domain' right?

i using acl on zend nav layout, user experience purposes; menu , links zend nav 'greyed', non-existant, or active (and visible) according user role, example 'user' role not many 'admin' options, , re-enforced acl in controller 1 not type url , area either.

my other thought maybe should thinking of moving login bootstrap situation, i'm not sure idea either?


edit: code put front controller plugin:

class plugins_controller_zendnavinit extends zend_controller_plugin_abstract {          public function predispatch(zend_controller_request_abstract $request) {              $auth = zend_auth::getinstance();              if ($auth->hasidentity()) {                  $config = new zend_config_xml(application_path . '/configs/navigation.xml', 'nav');                 $container = new zend_navigation($config);                 $acl = new application_model_acl_acl();                  $layout = zend_layout::getmvcinstance();                 $view = $layout->getview();                  $role = zend_auth::getinstance()->getidentity()->userrole;                 $view->navigation($container)->setacl($acl)->setrole($role);             }         }     } 

works great; of course, had register plugin other. moved auth checking front-controller plugin too.

you build anonymous role before login , handle short acl policy anonymous users. check this response example on how catch unauthentified users on predispatch auth plugin.


Comments