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

964 Views Asked by At

I am trying to change the path of index.php.

I have a boot strap zend structure.

So I created a new folder named newapp, its path is root path where our index.php lies.

Then I copied the index.php to newapp so that I can load the application from newapp directory.

But problem is that I can't load configuration file from index.php that I copied. It thorws error which is given below.

 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

Note my folder structure

- trunk

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

My actual index.php is given below

<?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();

What should I change in index.php ?

  • I tried change the path of config file as

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

but didn't work - Zend library is available beacuse I have set path variable to it from

enviornment variable settings of windows.

  • I tried this also realpath(dirname(__FILE__))."/.."

But application is not loaded.

2

There are 2 best solutions below

0
On
defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));
define('APPLICATION_PATH', BASE_PATH . '/application');
set_include_path('../../library1.12.0/'. get_include_path());

Should be this in newapp/index.php with the lines below

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()
)));

NOTE: folder 'library1.12.0' shoould be in application folder level and Zend folder should be inside it. Hope this will help you, i have tested it and its working.

1
On

try adding

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