Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APPLICATION_PATH in *.ini configuration, how does it work?

An *.ini file has a constant: APPLICATION_PATH

When is APPLICATION_PATH set and how does it work?

See the below code for instance

; application/configs/application.ini
 
[production]
; PHP settings we want to initialize
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
like image 316
vietean Avatar asked Dec 22 '22 07:12

vietean


1 Answers

APPLICATION_PATH is a PHP constant used by ZendFramework to determine where you deployed/installed your project. It's usually defined in newproject/public/index.php i.e.

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH',
              realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV',
              (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV')
                                         : 'production'));

/** Zend_Application */
require_once 'Zend/Application.php';

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

Application.ini is not a php class / file, it is a configuration file which means it follows a different syntax.

To concatenate strings and constants together, you simple put them next to each other, you don't use the dot (.) operator. One thing to watch out for is that you have to use double quotes ("), otherwise the constant will not be evaluated.

For more information, you can look into the documentation of the parse_ini() function, which is the function that's used by ZendFramework to parse configuration files.

References: http://php.net/manual/en/function.parse-ini-file.php http://php.net/manual/en/function.constant.php http://framework.zend.com/manual/en/zend.application.quick-start.html

like image 53
Mark Basmayor Avatar answered Feb 11 '23 19:02

Mark Basmayor