Invalid controller specified (error) - Zend Framework

I get it all the time:

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

I have an ErrorController.php file in the "controller" directory, which looks like this:

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

My download is as follows:

 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 
+4
source share
1 answer

You must rely on the resource loader / load to get your frontController, omit _initController()

To get your controller from the buffer, you can do $this->bootstrap('frontController'); and $frontController = $this->getResource('frontController'); . This way it will use the configuration in your application.ini application.

Regarding the bug, I think your problem might be the missing slash: APPLICATION_PATH . '/controllers/' APPLICATION_PATH . '/controllers/' , which you manually install in bootstrap. Your APPLICATION_PATH may not end with / , so it cannot find applicationcontrollers/ErrorController.php

Alternatively, your _initRoute() function can 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 run() controller to function try{}catch{} , which could be moved to your index.php .

+7
source

Source: https://habr.com/ru/post/1301488/


All Articles