2013-11-24 111 views
0

嘗試設置基於zend框架的應用程序時。我收到這個錯誤。致命錯誤:在非對象上調用成員函數getRoles()

Fatal error: Call to a member function getRoles() on a non-object in C:\xampp\htdocs\issues-master\application\modules\default\services\Acl.php on line 47

我經歷了代碼,沒有看到任何錯誤。下面是代碼,

/** 
* _setupRoles 
* 
* @return void 
*/ 
protected function _setupRoles() 
{ 
    $this->_roles = $this->_roleService->getAllRoles(); 
    foreach ($this->_roles as $i) { 
     $this->_acl->addRole($i); 
    } 
    $currentRoles = Zend_Registry::get('Default_DiContainer')->getUserService() 
     ->getIdentity()->getRoles(); 

    $this->_acl->addRole(new Zend_Acl_Role('user'), $currentRoles); 
} 

請讓我知道我在做什麼錯在這裏。

回答

0

這是因爲,我調用了一個使用非對象的方法。在我的情況下,

Zend_Registry::get('Default_DiContainer')->getUserService() 
     ->getIdentity() 

這是作爲一個值爲空,所以我無法調用getRoles();

可以在這裏找到另一個答案:RoleInterface throws "call on a non-object" error

相關問題