我试图在我的应用程序中集成Zend_Acl:
class AuthController extends Zend_Controller_Action
{
public function __construct (Zend_Auth $auth, Zend_Acl $acl)
{
$this->_auth = $auth;
$this->_acl = $acl;
}
}但我发现了一个错误:
Zend_Controller_Action_Interface::__construct() ()的
声明必须与.中的AuthController::__construct声明兼容。
有什么想法吗?
发布于 2012-06-01 01:04:38
构造函数的Zend_Controller_Action_Interface如下所示:
public function __construct(Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response,
array $invokeArgs = array());这意味着类必须对构造函数具有相同的声明。
发布于 2012-06-01 01:15:54
由于无法更改构造函数,因此必须以不同的方式传递ACL。还请记住,您可以随时通过调用Zend_Auth来访问Zend_Auth::getInstance()。
要访问ACL,可以使用Zend_Registry。如果要在引导程序中定义ACL,请将其放在注册表中。然后,您可以通过注册表访问它,甚至可以编写一个扩展Zend_Controller_Action的新类,该类提供了检索ACL的方法。
发布于 2012-06-01 07:10:25
您从不启动控制器实例,因为它是Zend_Controller_Front为您完成的任务,因此不能使用它的构造函数。但是你能做的是用Zend_Registry代替
在你的Bootstrap.php
Zend_Registry::set('acl',$acl);
Zend_Registry::set('auth',$auth);在你的控制器里
public function init()
{
$this->_acl = Zend_Registry::get('acl');
$this->_auth = Zend_Registry::get('auth');
}这个init函数充当构造函数。
https://stackoverflow.com/questions/10843157
复制相似问题