Jump to content

Zend_Controller_Dispatcher_Exception: Invalid controller specified (error)


ethereal1m

Recommended Posts

Dear all,

I'm using Zend Framework 1.10 with the following index.php file:

defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', '/srv/httpd/htdocs/Zend/application');

// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ?
getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini');
//$application->bootstrap()->run();

and my indexController.php looks like:

class IndexController extends Zend_Controller_Action
{
public function init()
{
	$this->_helper->viewRenderer->setNoRender();
}
public function indexAction()
{
	$this->getResponse()->appendBody('Hello from indexAction');
}
}

Also it has application.ini file:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

But when I debug the script looking at Zend_Application_Bootstrap_Bootstrap class on Bootstrap.php when running its run() function, inside it, Zend_Controller_Front object variable _cotrollerDir is not initialized, whereas bootstrap object ->options->resources->frontController->controllerDirectory is set.

 

Also I got the following error (exception):

Zend_Controller_Dispatcher_Exception: Invalid controller specified (error) in /var/www/htdocs/Zend/library/Zend/Controller/Dispatcher/Standard.php on line 242

 

So how come the controller directory is not recognized by Zend_Controller_Front? Any ideas?

Regards,

ethereal1m

Link to comment
Share on other sites

You have an error and it's trying to dispatch ErrorController which you are missing.

 

class ErrorController extends Zend_Controller_Action {
  public function errorAction() {
    $errorHandler = $this->_getParam('error_handler');
    var_dump($errorHandler);//does this contain an exception property?
    print $errorHandler->exception->getMessage();
  }
}

Link to comment
Share on other sites

Whenever you get an error (read Exception) your dispatcher will catch this otherwise uncaught Exception (to remain functional towards your end-users) and create an error handler (Zend_Controller_Plugin_ErrorHandler) object, add it to the internal messaging system, sets the active controller to ErrorController, and signals the dispatcher the request is yet unhandled (isDispatched(false)).

 

So your dispatcher tries to find and execute ErrorController which it can't find and therefor throws an Exception that isn't caught as the Dispatcher itself doesn't handle it's own Exception's.

 

In order to work with the Zend framework you need a deep understanding of it's internal workings. I suggest you familiarize yourself before digging any deeper as it's only getting more and more complex with each new release.

Link to comment
Share on other sites

well,ironically I'm learning zend framework by following a book hence stumbling upon this problem. But the book is using 1.8 ver and i'm using 1.10 lib, not sure if the version discrepancy is something to do with the error.

 

can i disable the error handler? like (I found this on the web but don't know how to incorporate it:

$this->frontController->setParam('noErrorHandler', TRUE);

or are you saying I should incorporate your ErrorController instead?

 

Also how come my controller directory is not recognized by the frontController?

Link to comment
Share on other sites

It has nothing to do with the version difference. And it's best to not disable the error handler as you otherwise will not be notified of any occured error's returning a blank page. And yes you should incorporate the ErrorController, it will tell you what the error is.

Link to comment
Share on other sites

hmm,

i created errorController.php with the code that you gave me, it still throws me the same error. Any ideas?

 

It has been a while since I used Zend framework I added a comment to my code that said you should check out what the error_handler object returned.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.