我有一个错误,实际上是错误,这是通知,但我仍然想修复它;
当我尝试访问带有null role
的页面时,它显示以下消息:
Notice: Trying to get property of non-object in C:ZendApache2htdocshotelrwandaapplicationpluginAccessCheck.php on line 18
如何修复它是我的脚本:
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$resource = $request->getControllerName();
$action = $request->getActionName();
$identity = $this->_auth->getStorage()->read();
$role = $identity->role;
if(!$this->_acl->isAllowed($role, $resource, $action)){
$request->setControllerName('users')
->setActionName('login');
}
}
行:18是这个行:$role = $identity->role;
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$resource = $request->getControllerName();
$action = $request->getActionName();
$role = 'guest'; //your default role
if(Zend_Auth::getInstance()->hasIdentity())
{
$role = Zend_Auth::getInstance()->getIdentity()->role;
}
if(!$this->_acl->isAllowed($role, $resource, $action)){
$request->setControllerName('users')
->setActionName('login');
}
}
这里的"来宾"充当默认角色。您可以随意命名它,但请确保在 ACL 中添加此角色并相应地授予此角色权限。