我是zend框架的新手,并尝试实现zend_acl.I创建了一个自定义插件并将其放入
myzend是我项目的目录。我正在尝试初始化这个自定义插件 使用
启动$frontController = Zend_Controller_Front::getInstance();
$frontController->setControllerDirectory('/path/to/controllers')
->setRouter(new Zend_Controller_Router_Rewrite())
->registerPlugin(new My_Controller_Plugin_Acl());
但我收到此错误消息
Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'Action index" does not exist and was not trapped in __call()' in C:\xampp\htdocs\zend\library\Zend\Controller\Action.php:485
Stack trace:
#0 C:\xampp\htdocs\zend\library\Zend\Controller\Action.php(518): Zend_Controller_Action->__call('indexAction', Array)
#1 C:\xampp\htdocs\zend\library\Zend\Controller\Dispatcher\Standard.php(308): Zend_Controller_Action->dispatch('indexAction')
#2 C:\xampp\htdocs\zend\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#3 C:\xampp\htdocs\zend\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#4 C:\xampp\htdocs\zend\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#5 C:\xampp\htdocs\zend\public\index.php(44): Zend_Application->run()
#6 {main} Next exception 'Zend_Controller_Exception' with message 'Action "index" does not exist and in C:\xampp\htdocs\zend\library\Zend\Controller\Plugin\Broker.php on line 336
请指导我。提前谢谢。
答案 0 :(得分:0)
将您的插件放入library/Controller/Plugin/Acl.php
,然后将其添加到您的应用程序中(建议使用Bootstrap)。
//register your folder with aoutloader
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('My_');
//register your plugin
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin(new My_Controller_Plugin_Acl());
您的代码更改了默认的Controller目录,因此Zend无法找到正确的操作
答案 1 :(得分:0)
在preDispatch()方法的重定向中,试试这个:
$request->setActionName('error');
而不是:
$request->setActionName('index');
如果你想犯错误,试试这个:
throw new Zend_Acl_Exception("Not allowed");
而不是
$request->setControllerName('Error');
$request->setActionName('index');