2010-02-16 60 views
4

我得到這一切錯誤的時間:無效的控制器所指定的(錯誤) - Zend框架

exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in blub\libraries\Zend\Controller\Dispatcher\Standard.php:242

我有一個文件「ErrorController.php」中的「控制器」目錄看起來像這樣:

class ErrorController extends Zend_Controller_Action 
{ 
    public function errorAction() 
    { 
     // blub 
    } 
} 

我舉看起來是這樣的:

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 

回答

7

您應該依靠資源加載器/引導,讓您的frontController,刪除_initController()

若要從自舉得到你的控制器,你可以做$this->bootstrap('frontController');$frontController = $this->getResource('frontController');。這樣它將使用你的application.ini中的配置。

只要錯誤發生,我認爲你的問題可能是缺少的斜線:APPLICATION_PATH . '/controllers/',你手動設置在引導程序中。您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" 

這使得你的自舉的只是一部分希望控制器的run()函數的try{}catch{}可以改爲您的index.php