4

我似乎遇到了一个问题,即使用 Zend_Config 对象加载 Zend_Application 对象与使用文件名加载 Zend_Application 对象产生不同的结果。为了说明我的观点,我有以下两种加载方法,第一种有效(请注意,此时也定义了所有常量:

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

这个不起作用并给我错误:

致命错误:在 /var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php:91 中未捕获的异常“Zend_Application_Bootstrap_Exception”和消息“没有向前端控制器注册的默认控制器目录”

堆栈跟踪:#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} 在第 91 行抛出 /var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php

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

他们都使用相同的文件,如下所示:

[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

我的目录结构看起来像这样,重要的文件夹展开了。

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

所以重申一下,使用 Zend_Application 的构造函数中的文件名加载 INI 文件会产生预期的结果(工作应用程序)。将 Config 对象传递给 Zend_Application 的构造函数会给我上述错误。

关于为什么这会有所作为的任何线索?

4

3 回答 3

1

就我而言,外壳不匹配。最初的默认目录是在没有驼峰式大小写的情况下声明的,而我需要添加的前端控制器目录确实是用大小写的。

所以这就是我所拥有的:

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

总而言之,ZF 在对应用程序资源进行初始查找时没有考虑大小写。然而,已经实例化的资源的后续查找必须匹配第一个声明的大小写。

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;
}
于 2012-05-29T20:42:06.353 回答
0

试试这个我有同样的问题:

这是我的解决方案

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

代替

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

于 2012-04-29T15:00:46.023 回答
0

致命错误:在 /var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php:91 中未捕获的异常“Zend_Application_Bootstrap_Exception”和消息“没有向前端控制器注册的默认控制器目录”

堆栈跟踪:#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} 在第 91 行抛出 /var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php

您的错误消息说没有默认控制器注册到前端控制器对象。发生这种情况是因为您尝试使用 Zend_Config 并且它可能没有以正确的方式加载数组。

你能用 Zend_Debug 打印 $appConfig 变量并将结果发布给我们更好地帮助你吗?

于 2011-11-23T12:03:09.407 回答