使用 application.ini 来配置 Zend_Application Bootstrap
我已经为我的 Zend_Application 引导程序编写了自定义资源。
在 手册给出了用于加载它们的以下代码:
$application = new Zend_Application(APPLICATION_ENV, array(
'pluginPaths' => array(
'My_Resource' => APPLICATION_PATH . '/resources/',
),
'resources' => array(
'FrontController' => array(
'controllerDirectory' => APPLICATION_PATH . '/controllers',
),
),
));
但是,这并没有使用我想要使用的application.ini。是否可以从我的 application.ini 中完全配置它?
我的最终解决方案:(在Will的回答的帮助下):
- 使用zf.sh create project(版本1.9.6)创建一个空项目
在application/resources/Ftp.php中创建以下类
class My_Resource_Ftp 扩展 Zend_Application_Resource_ResourceAbstract { 受保护的 $_params = array(); 公共函数 init() { echo "init 被调用"; 返回数组(“嘿”); } }
以下 application.ini
<前><代码>[生产] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH“/../library” bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "引导程序" pluginPaths.My_Resource = APPLICATION_PATH“/资源/” resources.frontController.controllerDirectory = APPLICATION_PATH“/controllers” resources.ftp.用户名=“我” [分期:制作] [测试:生产] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [开发:生产] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1
I have written custom resources for my Zend_Application bootstrap.
In the manual the following code is given for loading them:
$application = new Zend_Application(APPLICATION_ENV, array(
'pluginPaths' => array(
'My_Resource' => APPLICATION_PATH . '/resources/',
),
'resources' => array(
'FrontController' => array(
'controllerDirectory' => APPLICATION_PATH . '/controllers',
),
),
));
This however does not make use of the application.ini which I want to use. Is there a possibility to configure this completely from my application.ini?
My final solution: (with help of Will's answer):
- create an empty project with zf.sh create project (version 1.9.6)
make the following class in application/resources/Ftp.php
class My_Resource_Ftp extends Zend_Application_Resource_ResourceAbstract { protected $_params = array(); public function init() { echo "init invoked"; return array("hey"); } }
The following application.ini
[production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" pluginPaths.My_Resource = APPLICATION_PATH "/resources/" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.ftp.username = "me" [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您只需使用 application.ini 的路径作为构造函数的第二个参数,例如:
这是快速入门指南采用的方法:http://framework.zend.com/manual/en/zend.application.quick-start.html
在您的 .然后,您将在 ini 文件中添加资源路径,例如:
Yes, you just have to use the path to your application.ini as the second argument to the constructor, e.g:
This is the approach the quick start guide takes: http://framework.zend.com/manual/en/zend.application.quick-start.html
In your .ini file you would then add resource paths like: