将index.php从zend框架中的应用程序根目录中移出


Moving index.php out of application root in zend frame work

我正在尝试更改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的environment变量设置。

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

但应用程序未加载。

尝试添加

set_include_path(
  APPLICATION_PATH.'/../library1.12.0'.PATH_SEPARATOR.
      APPLICATION_PATH.'/../library1.12.0/Zend'
);
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文件夹应该在里面。希望这能对你有所帮助,我已经测试过了。