【问题标题】:Moving index.php out of application root in zend frame work在 zend 框架中将 index.php 移出应用程序根目录
【发布时间】:2013-05-17 10:57:00
【问题描述】:

我正在尝试更改 index.php 的路径。

我有一个引导带 zend 结构。

于是我新建了一个文件夹,名字叫newapp,它的路径就是我们的index.php所在的根路径。

然后我将 index.php 复制到 newapp 以便我可以从 newapp 目录加载应用程序。

但问题是我无法从我复制的 index.php 加载配置文件。它会引发下面给出的错误。

 Fatal error: Uncaught exception 'Zend_Config_Exception' with message 

'parse_ini_file(E:\xampp\htdocs\..../configs/application.ini) [<a href='function.parse-

ini-file'>function.parse-ini-file</a>]: failed to open stream: No such file or directory' 

in E:\xampp\htdocs\ZendFramework-1.12.0\library\Zend\Config\Ini.php:182

注意我的文件夹结构

- trunk

        - index.php
        - application
            - bootstrap.php
            - configs
                - config.ini
        - newapp
            - index.php (copy of above)

我的实际 index.php 如下所示

<?php
    ini_set('memory_limit', '-1');
    set_time_limit(0);
    defined('BASE_PATH')|| define('BASE_PATH', realpath(dirname(__FILE__)));
    define('APPLICATION_PATH', BASE_PATH . '/application');

    set_include_path('../../library1.12.0/'. get_include_path());

    require_once 'Zend/Loader/Autoloader.php';
    $loader = Zend_Loader_Autoloader::getInstance();
    $loader->setFallbackAutoloader(true);

    defined('APPLICATION_ENV')|| define('APPLICATION_ENV',(getenv

('APPLICATION_ENV') ? getenv('APPLICATION_ENV'): 'staging_mysql'));


    $application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
    );
    $application->bootstrap();
    $application->run();

我应该在 index.php 中更改什么?

  • 我尝试将配置文件的路径更改为

    APPLICATION_PATH 。 '/../../configs/application.ini'

但没用 - Zend 库可用,因为我已经从

设置了路径变量

windows环境变量设置

  • 我也试过这个realpath(dirname(__FILE__))."/.."

但应用程序未加载。

【问题讨论】:

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


    【解决方案1】:

    尝试添加

    set_include_path(
      APPLICATION_PATH.'/../library1.12.0'.PATH_SEPARATOR.
          APPLICATION_PATH.'/../library1.12.0/Zend'
    );
    

    【讨论】:

    • 我试过了,但是:警告:require_once(Zend/Loader/Autoloader.php) [function.require-once]:打开流失败:
    【解决方案2】:
    defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));
    define('APPLICATION_PATH', BASE_PATH . '/application');
    set_include_path('../../library1.12.0/'. get_include_path());
    

    应该在 newapp/index.php 中使用以下行

    defined('BASE_PATH')|| define('BASE_PATH', realpath(dirname(__FILE__)));
    defined('APPLICATION_PATH')
        || define('APPLICATION_PATH', BASE_PATH . '/../../application');
    
    // Ensure library/ is on include_path
    set_include_path(implode(PATH_SEPARATOR, array(
        realpath(APPLICATION_PATH . '/../library1.12.0'),
        get_include_path()
    )));
    

    注意: 文件夹“library1.12.0”应该在应用程序文件夹级别,Zend 文件夹应该在其中。希望这会对您有所帮助,我已经对其进行了测试并且可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-10
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      • 2011-09-09
      相关资源
      最近更新 更多