4

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"

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

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.