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



我似乎遇到了一个问题,用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();

这个不工作,给了我错误:

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

堆栈跟踪:#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}抛出/var/www/roommateexpensebuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php第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();

他们都使用了相同的文件,看起来像这样:

[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文件会产生预期的结果(工作应用程序)。在Zend_Application的构造函数中传递Config对象会导致上面的错误。

你知道为什么这会产生不同吗?

在我的例子中,与大小写不匹配。最初的默认目录没有使用驼峰大小写,而我需要添加的前端控制器目录确实使用了大小写。

那么这就是我所拥有的:

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;
}

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

堆栈跟踪:#0/var/www/roommateexpensebuddy/allan/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()

/var/www/RoommateExpenseBuddy/艾伦/公共/index . php (36): Zend_Application→运行()

{main}抛出/var/www/roommateexpensebuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php第91行

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

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

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

这是我的解决方案

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

不是

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

相关内容

  • 没有找到相关文章

最新更新