开发者

Invalid controller specified (error) - Zend Framework

开发者 https://www.devze.com 2022-12-20 20:38 出处:网络
I get all the time this error: exception \'Zend_Controller_Dispatcher_Exception\' with message \'Invalid controller specified (error)\' in blub\\libraries\\Zend\\Controller\\Dispatcher\\Standard.php

I get all the time this error:

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

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"

reso开发者_运维问答urces.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


You should rely on the resource loader/bootstrap to get your frontController, drop the _initController()

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.

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

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"

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消