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

时间:2011-10-22 15:22:58

标签: php zend-framework zend-application zend-config

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

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

致命错误:未捕获的异常'Zend_Application_Bootstrap_Exception',并在/var/www/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()

第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();

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

[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对象会给我上面的错误。

有关为何会产生影响的任何线索?

3 个答案:

答案 0 :(得分: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;
}

答案 1 :(得分:0)

  

致命错误:未捕获的异常'Zend_Application_Bootstrap_Exception',并在/var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php:91

中显示消息'未向前端控制器注册默认控制器目录'      

堆栈追踪:#0 /var/www/RoommateExpenseBuddy/allan/library/Zend/Application.php(366):Zend_Application_Bootstrap_Bootstrap-&gt; run()

     

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

     第91行/var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php中

{main}

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

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

答案 2 :(得分:0)

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

这是我的解决方案

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

而不是

resources.frontController.controllerDirectory = APPLICATION_PATH“/ controllers”