gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 23:43:23 24 4
gpt4 key购买 nike

我似乎遇到了一个问题,即使用 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 :在/var/www/RoommateExpenseBuddy/allan/library/Zend/Application/Bootstrap/Bootstrap.php:91 中出现未捕获的异常“Zend_Application_Bootstrap_Exception”和消息“没有使用前端 Controller 注册的默认 Controller 目录”

堆栈跟踪:#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 的构造函数会出现上述错误。

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

最佳答案

在我的例子中,外壳不匹配。原始默认目录声明时没有驼峰式大小写,而我需要添加的前端 Controller 目录确实有大小写。

这就是我所拥有的:

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

关于php - 为什么用 Zend_Config 对象加载 Zend_Application 会产生与发送文件名不同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7860539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com