使用 application.ini 来配置 Zend_Application Bootstrap

发布于 2024-08-17 10:08:21 字数 1621 浏览 18 评论 0原文

我已经为我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挖鼻大婶 2024-08-24 10:08:21

是的,您只需使用 application.ini 的路径作为构造函数的第二个参数,例如:

$application = new Zend_Application(
  APPLICATION_ENV,
  APPLICATION_PATH . '/config/application.ini'
);

这是快速入门指南采用的方法:http://framework.zend.com/manual/en/zend.application.quick-start.html

在您的 .然后,您将在 ini 文件中添加资源路径,例如:

pluginPaths.My_Resource = APPLICATION_PATH "/resources/"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

Yes, you just have to use the path to your application.ini as the second argument to the constructor, e.g:

$application = new Zend_Application(
  APPLICATION_ENV,
  APPLICATION_PATH . '/config/application.ini'
);

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:

pluginPaths.My_Resource = APPLICATION_PATH "/resources/"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文