简体   繁体   English

为什么使用Zend_Config对象加载Zend_Application会产生与发送文件名不同的结果?

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

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. 我似乎遇到一个问题,即使用Zend_Config对象加载Zend_Application对象会产生与使用文件名加载Zend_Application对象不同的结果。 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 致命错误:/var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php:91中未捕获的异常'Zend_Application_Bootstrap_Exception',消息'未向前端控制器注册默认控制器目录'

Stack trace: #0 /var/www/RoommateExpenseBuddy/allan/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 堆栈跟踪:#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() #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 在第91行的/var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php中抛出#2 {main}

/** 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 = "info@associateinnovations.com"
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). 重申一下,在Zend_Application的构造函数中使用文件名加载INI文件会产生预期的结果(工作应用程序)。 Passing a Config object inot the constructor of Zend_Application gives me the above error. 在Zend_Application的构造函数中传递Config对象给出了上述错误。

Any clue as to why this would make a difference? 任何线索,为什么这会有所作为?

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. 总而言之,在对应用程序资源进行初始查找时,ZF没有考虑外壳。 Subsequent lookups of the already instantiated resource have to match the case of the first declaration, however. 然而,对已经实例化的资源的后续查找必须匹配第一个声明的情况。

Zend_Application_Bootstrap_BootstrapAbstract::_resolvePluginResourceName 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;
}

Try this I had the same problem: 试试这个我有同样的问题:

This was my solution 这是我的解决方案

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

instead of 代替

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontController.controllerDirectory = APPLICATION_PATH“/ controllers”

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 致命错误:/var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php:91中未捕获的异常'Zend_Application_Bootstrap_Exception',消息'未向前端控制器注册默认控制器目录'

Stack trace: #0 /var/www/RoommateExpenseBuddy/allan/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 堆栈跟踪:#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() /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 {main}投放在第91行的/var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php

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. 这种情况正在发生,因为您正在尝试使用Zend_Config,并且可能无法以正确的方式加载阵列。

Could you print the $appConfig var with Zend_Debug and post the result to we better help you? 你能用Zend_Debug打印$ appConfig var并将结果发布给我们更好的帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM