views:

413

answers:

1

When I load the homepage of a ZF site I get a message saying "Invalid controller specified (error)" where "error" seems to be the name of the controller.

In my bootstrap.php I have the snippet below where I added the prints statement in the catch():

// Dispatch the request using the front controller. 
try {   
    $frontController->dispatch();
}
catch (Exception $exception) {
    print $exception; exit;
    exit($exception->getMessage());
}

This prints out:

exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in /www/common/ZendFramework/library16/Zend/Controller/Dispatcher/Standard.php:241
Stack trace:
#0 /www/common/ZendFramework/library16/Zend/Controller/Front.php(934): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 /www/site.com/htdocs/application/bootstrap.php(38): Zend_Controller_Front->dispatch()
#2 /www/site.com/htdocs/public/index.php(16): require('/www/site....')
#3 {main}

Can anyone make sense out of what it going on? I have a hunch it has something to do with case sensitivity and the naming conventions of ZF.

The initial "invalid controller" message comes from the snippet below

print $request->getControllerName();

        if (!$this->isDispatchable($request)) {
            $controller = $request->getControllerName();
            if (!$this->getParam('useDefaultControllerAlways') && !empty($controller)) {
                require_once 'Zend/Controller/Dispatcher/Exception.php';
                throw new Zend_Controller_Dispatcher_Exception('Invalid controller specified (' . $request->getControllerName() . ')');
            }
            $className = $this->getDefaultControllerClass($request);

        }

This all prints out "indexerrorInvalid controller specified (error)" so it looks like it's trying to load the index controller first, can not and then has a problem loading the error controller.

Could it just be that the path to the controller files is wrong?

A: 

Hi !, in your case the frontcontroller is trying to reach to the index (homepage) of your site but he couldn't reach it because there is some error in your path to the controller directory after he fails to do that there is a controller plugin called "Zend_Controller_Plugin_ErrorHandler" and this one is registered by default so it forward the request to the error controller which is also not found by the front controller so he said to you this error

so check the path to your controller directory

i hope i'd explain it well to you :)

Okey,

Follow along with me : this code should found in index.php file

<?php
error_reporting(E_ALL || E_STRICT);

define('APPLICATION_PATH' , realpath(dirname(__FILE__)) .'/../application' );


set_include_path(
    APPLICATION_PATH . '/../library'
    . PATH_SEPARATOR . get_include_path()
);

require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();



try
{
    require '../application/bootstrap.php';
}
catch(Exception $exception)
{
    echo "<html><body> an exception occured while bootstrapping the application";

    if (defined('APPLICATION_ENVIRONMENT') && APPLICATION_ENVIRONMENT != 'production')
    {
     echo "<br/><br/>" . $excepion->getMessage() . "<br/>"
     . "<div align='left'>Stack Trace: "
     . "<pre> " . $exception->getTraceAsString() . "</pre></div>";
    }
    echo "</body></html";
    exit(1);
}

Zend_Controller_Front::getInstance()->dispatch();

and I guess now you had an file called "Application" , "bootstrap" or "initlizer" what ever named it should looks like

<?php

defined('APPLICATION_PATH')
    or define('APPLICATION_PATH' , dirname(__FILE__));

defined('APPLICATION_ENVIRONMENT')
    or define('APPLICATION_ENVIRONMENT', 'development');



$frontController = Zend_Controller_Front::getInstance();

$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');


$frontController->setParam('env' , APPLICATION_ENVIRONMENT);


Zend_Layout::startMvc(APPLICATION_PATH . '/layouts/scripts');


$view = Zend_Layout::getMvcInstance()->getView();
$view->doctype('XHTML1_STRICT');

unset($frontController);

you should double check this line :

  $frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');

it sets the path to the ControllerDirectory

tawfekov
Thanks for your comment. Do you have any idea where these paths would be set? I have require_once 'Zend/Controller/Front.php'; in Initializer.php and that seems correct
stef
i dont really what your ZF version so i will refer to ZF Quick start http://bit.ly/67TK8d but if you are using ZF1.8 or higher check out your config file and look for something like : resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"resources.frontController.defaultControllerName = "index"
tawfekov
When I run a filesearch for "defaultControllerName", nothing shows up. I think I'm using ZF 1.6. Could it be these settings are stored in a different way?
stef
i had updated my answer above so search the code for "$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');" dont search the files
tawfekov
fixed it - there was an issue with the rights on the IndexController parent folder that only the server admin could fix.Thanks for pointing me in the right direction!
stef