Why would loading a Zend_Application with a Zend_Config object produce different results from sending the file name?

3.2k views Asked by At

I seem to be having an issue where loading my Zend_Application object with a Zend_Config object produces different results than loading the Zend_Application object with a filename instead. To illustrate my point, I have the two following methods of loading, the first of which works (Mind you all the constants are defined at this point as well:

/** 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();

This one doesn't work and gives me the error:

Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'No default controller directory registered with front controller' in /var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php:91

Stack trace: #0 /var/www/RoommateExpenseBuddy/allan/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()

#1 /var/www/RoommateExpenseBuddy/allan/public/index.php(36): Zend_Application->run()

#2 {main} thrown in /var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php on line 91

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

They both are using the same file which looks like this:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
emailNotice.email = "[email protected]"
emailNotice.name = "Roommate Expense Buddy"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.defaultmodule = "global"
resources.frontController.params.prefixDefaultModule = true
resources.db.adapter = "PDO_MYSQL"
resources.db.isdefaulttableadapter = true
resources.db.params.dbname = "db_name"
resources.db.params.username = "db_user"
resources.db.params.password = "mypassword"
resources.db.params.hostname = "localhost"
resources.db.params.charset = "UTF8"
invitation.defaultViewPath = APPLICATION_PATH "/modules/global/views/scripts/invitation"

[staging : production]

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

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

My Directory structure looks something like this with the important folders expanded.

|~application/
| |~configs/                  
| | |-application.ini                          
| | `-navigation.xml
| |+helpers/
| |+layouts/ 
| |+migrations/
| |~modules/
| | `~global/
| |   |+controllers/ 
| |   |+forms/  
| |   |+models/                                                                    
| |   `+views/                                                                    
| `-Bootstrap.php                                                                 
|+bin/                                                                              
|+data/                                                                            
|+docs/                                                                             
|+library/                                                                       
|+public/                                                                        
`+tests/ 

So to reiterate, Loading an INI file using the filename in the constructor of Zend_Application produces expected results (working app). Passing a Config object inot the constructor of Zend_Application gives me the above error.

Any clue as to why this would make a difference?

3

There are 3 answers

0
Zachary Schuessler On

In my case there was a mismatch with casing. The original default directory was declared without camel casing, while a front controller directory I needed to add was indeed cased.

So this is what I had:

resources.frontcontroller.controllerDirectory.default   = APPLICATION_PATH "/default/controllers"
resources.frontController.controllerDirectory.mydir     = APPLICATION_PATH "/default/controllers"

To summarize, ZF isn't taking into account casing when doing the initial lookup for the application resource. Subsequent lookups of the already instantiated resource have to match the case of the first declaration, however.

Zend_Application_Bootstrap_BootstrapAbstract::_resolvePluginResourceName

/**
 * Resolve a plugin resource name
 *
 * Uses, in order of preference
 * - $_explicitType property of resource
 * - Short name of resource (if a matching prefix path is found)
 * - class name (if none of the above are true)
 *
 * The name is then cast to lowercase.
 *
 * @param  Zend_Application_Resource_Resource $resource
 * @return string
 */
protected function _resolvePluginResourceName($resource)
{
    if (isset($resource->_explicitType)) {
        $pluginName = $resource->_explicitType;
    } else  {
        $className  = get_class($resource);
        $pluginName = $className;
        $loader     = $this->getPluginLoader();
        foreach ($loader->getPaths() as $prefix => $paths) {
            if (0 === strpos($className, $prefix)) {
                $pluginName = substr($className, strlen($prefix));
                $pluginName = trim($pluginName, '_');
                break;
            }
        }
    }
    $pluginName = strtolower($pluginName);
    return $pluginName;
}
0
Ademir Mazer Jr - Nuno On

Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'No default controller directory registered with front controller' in /var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php:91

Stack trace: #0 /var/www/RoommateExpenseBuddy/allan/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()

/var/www/RoommateExpenseBuddy/allan/public/index.php(36): Zend_Application->run()

{main} thrown in /var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php on line 91

Your error message says that no default controller is registered to front controller object. This is happening cause you are trying to use Zend_Config and it may be not loading the array in the right way.

Could you print the $appConfig var with Zend_Debug and post the result to we better help you?

1
Fernando André On

Try this I had the same problem:

This was my solution

resources.frontController.controllerDirectory.default = APPLICATION_PATH "/controllers"

instead of

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"