【发布时间】:2014-01-06 08:22:54
【问题描述】:
我正在尝试创建一个用于创建菜单的操作助手。 但是我不知道为什么它不知道函数isAllowed。我收到以下错误消息:
在非对象上调用成员函数 isAllowed()
<?php
class Zend_Controller_Action_Helper_Menu extends Zend_Controller_Action_Helper_Abstract
{
private $_acl;
public function createSubMenu($request,$identity){
$controller = $request->getControllerName();
$action = $request->getActionName();
$identity = $identity->user_role;
$access = $this->hasAccess($identity,$action,$controller);
$return;
$return .= "<ul>";
$return .= "<li><a href=''>".$identity."</a></li>";
$return .= "</ul>";
return $access;
}
private function hasAccess($role, $action, $controller)
{
$this->_acl = new Zend_Acl();
if (!$this->_acl) {
$this->_acl = Zend_Controller_Front::getInstance()->getPlugin('Acl');
}
return $this->_acl->isAllowed($role, $controller, $action);
}
}
【问题讨论】:
-
如果设置了 $this->_acl is 那么你需要使用它,而不是 $acl。 (不要使用 Zend,所以我可能是错的)。
-
我仍然收到相同的错误消息,我更新了它现在工作的问题我需要实例化 Zend_Acl 也谢谢
-
@웃웃웃웃웃 停止你的编辑狂潮,我已将你标记为版主注意。
标签: php function zend-framework frameworks helper