Por*_*oru 4 php zend-framework
我总是得到这个错误:
异常'Zend_Controller_Dispatcher_Exception',在blub\libraries\Zend\Controller\Dispatcher\Standard.php中显示消息'指定了无效的控制器(错误)':242
我在"controllers"目录中有一个文件"ErrorController.php",如下所示:
class ErrorController extends Zend_Controller_Action
{
public function errorAction()
{
// blub
}
}
Run Code Online (Sandbox Code Playgroud)
我的引导程序看起来像这样:
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());
}
}
Run Code Online (Sandbox Code Playgroud)
的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
Run Code Online (Sandbox Code Playgroud)
你应该依靠资源加载器/ bootstrap来获取你的frontController,删除它 _initController()
为了充分利用自举控制器,你可以做$this->bootstrap('frontController');和$frontController = $this->getResource('frontController');.这样它将使用application.ini中的配置.
就错误而言,我认为您的问题可能是缺少的斜线:APPLICATION_PATH . '/controllers/'您在引导程序中手动设置.你APPLICATION_PATH可能不会以a结尾/,因此无法找到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"
Run Code Online (Sandbox Code Playgroud)
这使得想要控制你的引导程序的只有部分run()功能的try{}catch{}可能移动到您的index.php来代替.