Application Configurations

Application configurations are used to specify the global behavior of an application. They include specification of path aliases, namespace usages, module and service configurations, and parameters.

Configuration for an application is stored in an XML file named application.xml, which should be located under the application base path. Its format is shown in the following. Complete specification of application configurations can be found in the DTD and XSD files.

An external configuration file has the same format as described above. Although the name of the root element does not matter, it is recommended to be <configuration>. External configurations will append to the main configuration. For example, if a path alias is specified in an external configuration, it will become available in addition to those aliases specified in the main configuration.

By default without explicit configuration, a PRADO application will load a few core modules, such as THttpRequest, THttpResponse, etc. It will also provide the TPageService as a default service. Configuration and usage of these modules and services are covered in individual sections of this tutorial. Note, if your application takes default settings for these modules and service, you do not need to provide an application configuration. However, if these modules or services are not sufficient, or you want to change their behavior by configuring their property values, you will need an application configuration.

By default PRADO instanciates all modules defined in the application configuration at the beginning of the application lifecycle. This can hit the application performance if you have a lot of modules defined but not used at every request. Since version 3.2.2 you can set the lazy property on modules defined in the application configuration to enable the lazy loading of that module. A module with the lazy property set won't be instanciated until the first time it gets actually used by the application: // requesting the lazy module to the application will instanciate it Prado::getApplication()->getModule('ModuleID');

Since version 3.2 the application configuration can be stored in PHP array format in a file named application.php. The format of the configuration file is exactly the same of its XML counterpart, but following the PHP syntax.

array( 'PropertyName' => 'PropertyValue' ), 'modules' => array( 'ModuleID' => array( 'class' => 'ModuleClass', 'properties' => array( 'PropertyName' => 'PropertyValue' ), ), ), 'services' => array( 'ServiceID' => array( 'class' => 'ServiceClass', 'properties' => array( 'PropertyName' => 'PropertyValue' ), ), ), ); The use of a PHP application configuration must be defined in the TApplication constructor, tipically located in the index.php entry script: $application=new TApplication('protected',false,TApplication::CONFIG_TYPE_PHP); $application->run();