指定的控制器无效(错误) - Zend Framework [英] Invalid controller specified (error) - Zend Framework
问题描述
我一直收到这个错误:
在 blub\libraries\Zend\Controller\Dispatcher\Standard.php:242 中出现消息指定控制器无效(错误)"的异常Zend_Controller_Dispatcher_Exception"
exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in blub\libraries\Zend\Controller\Dispatcher\Standard.php:242
我在controllers"目录中有一个文件ErrorController.php",如下所示:
I have a file "ErrorController.php" in the "controllers" directory looking like this:
class ErrorController extends Zend_Controller_Action
{
public function errorAction()
{
// blub
}
}
我的引导程序如下所示:
My bootstrap looks like this:
protected function _initController()
{
$this->_frontcontroller = Zend_Controller_Front::getInstance();
$this->_frontcontroller->setControllerDirectory(APPLICATION_PATH . 'controllers/');
}
protected function _initRoute()
{
$this->_route = $this->_frontcontroller->getRouter();
$this->_route->addRoute('default', new Zend_Controller_Router_Route(
':controller/:action/*', array(
'module' => 'default',
'controller' => 'index',
'action' => 'index'
)
));
}
public function run()
{
try {
$this->_frontcontroller->dispatch();
}
catch (Exception $e) {
print nl2br($e->__toString());
}
}
application.ini
[bootstrap]
autoloadernamespaces[] = "Zend_"
autoloadernamespaces[] = "ZendX_"
[production]
includePaths.library = APPLICATION_PATH "/libraries"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.throwexceptions = 0
resources.frontController.params.displayExceptions = 0
[development : production]
resources.frontcontroller.params.throwexceptions = 1
resources.frontController.params.displayExceptions = 1
推荐答案
你应该依靠资源加载器/引导程序来获取你的 frontController,删除 _initController()
You should rely on the resource loader/bootstrap to get your frontController, drop the _initController()
要从 boostrap 中获取控制器,您可以执行 $this->bootstrap('frontController');
和 $frontController = $this->getResource('frontController');
.这样,它将使用您的 application.ini 中的配置.
To get your controller from the boostrap, you can do $this->bootstrap('frontController');
and $frontController = $this->getResource('frontController');
. This way it will use the configuration in your application.ini.
就错误而言,我认为您的问题可能是缺少斜线: APPLICATION_PATH .'/controllers/'
您在引导程序中手动设置.您的 APPLICATION_PATH
可能不以 /
结尾,因此它找不到 applicationcontrollers/ErrorController.php
As far as the error goes, I think your problem might be the missing slash on: APPLICATION_PATH . '/controllers/'
that you are manually setting in the bootstrap. Your APPLICATION_PATH
might not end with a /
, therefore it can't find applicationcontrollers/ErrorController.php
此外,您的 _initRoute()
函数可以替换为以下 application.ini:
Also, your _initRoute()
function could be replaced with the following application.ini:
resources.router.routes.default.type = "Zend_Controller_Router_Route"
resources.router.routes.default.route = ":controller/:action/*"
resources.router.routes.default.defaults.controller = "index"
resources.router.routes.default.defaults.action = "index"
resources.router.routes.default.defaults.module = "default"
这留下了引导程序的唯一部分,它希望控制器将 run()
函数的 try{}catch{}
移动到您的 index.php
代替.
This leaves the only part of your bootstrap that wants the controller the run()
function's try{}catch{}
which could be moved to your index.php
instead.
这篇关于指定的控制器无效(错误) - Zend Framework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!