我总是遇到这个错误:
exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in blub\libraries\Zend\Controller\Dispatcher\Standard.php:242
我在“ Controller ”目录中有一个文件“ErrorController.php”,如下所示:
class ErrorController extends Zend_Controller_Action
{
public function errorAction()
{
// blub
}
}
我的 Bootstrap 看起来像这样:
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
最佳答案
你应该依靠资源加载器/ Bootstrap 来获取你的 frontController,删除 _initController()
要从 boostrap 获取 Controller ,您可以执行 $this->bootstrap('frontController');
和 $frontController = $this->getResource('frontController');
。这样它将使用您的 application.ini 中的配置。
就错误而言,我认为您的问题可能是缺少斜杠:APPLICATION_PATH。 '/controllers/'
您在 Bootstrap 中手动设置的。您的 APPLICATION_PATH
可能没有以 /
结尾,因此找不到 applicationcontrollers/ErrorController.php
此外,您的 _initRoute()
函数可以替换为以下 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"
这留下了您的 Bootstrap 中唯一需要 Controller run()
函数的 try{}catch{}
的部分,它可以移动到您的 index .php
代替。
关于php - 指定的 Controller 无效(错误)- Zend Framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2276094/