Chapter: Configuration files
« Core workflow | ^ Main concepts | Developing a module » |
− Table of content
A Jelix application have several configuration files:
- A project.xml file, describing general information about the application
- A module.xml file in each module
- A defaultconfig.ini.php file for the global configuration, and a config.ini.php file for each entry points
- A profiles.ini.php for connections profiles (database configuration for example).
All are automatically generated when you create an application or a module. However, you have to modify them to bring additionnal information or to change parameters.
This chapter presents these files. See the chapter on configuration details to know more.
The project.xml file ¶
The file project.xml
contains some informations on the application. Some of these are important because they are used by the installer. Here is an example:
<?xml version="1.0" encoding="iso-8859-1"?>
<project xmlns="http://jelix.org/ns/project/1.0">
<info id="testapp@jelix.org" name="testapp" createdate="2005-01-01">
<version>1.3</version>
<label lang="en-EN">Testapp</label>
<description lang="en-EN">Application to test Jelix</description>
<licence URL="http://www.gnu.org/licenses/gpl.html">GPL</licence>
<copyright>2005-2011 Laurent Jouanneau and other contributors</copyright>
<creator name="Laurent Jouanneau" email="laurent@jelix.org" active="true" />
<homepageURL>http://jelix.org</homepageURL>
</info>
<dependencies>
<jelix minversion="1.3" maxversion="1.3.*" />
</dependencies>
<directories>
<config>var/config</config>
<log>var/log</log>
<var>var</var>
<www>www</www>
<temp>../temp/testapp</temp>
</directories>
<entrypoints>
<entry file="index.php" config="index/config.ini.php" />
<entry file="soap.php" config="soap/config.ini.php" type="soap"/>
</entrypoints>
</project>
The module.xml file ¶
A module.xml
file must be present in each directory of modules. It describes some general information, and dependencies with other modules.
<module xmlns="http://jelix.org/ns/module/1.0">
<info id="jelix_tests@testapp.jelix.org" name="jelix_tests">
<version>1.0</version>
<label>Jelix tests</label>
<description>unit tests for jelix</description>
</info>
<dependencies>
<jelix minversion="1.3" maxversion="1.3.*" />
<module name="testurls" minversion="1.0.2" maxversion="1.1b1" />
<module name="jauthdb" />
<module name="jacl2db" />
<module name="jacldb" />
</dependencies>
</module>
Configuration ini files ¶
Jelix framework configuration is stored in an ini-like file. It is a file structured by sections ([section name]
). Each section is a collection of parameter-name=value
pairs. There is a generic section, un-named, usually at the start of such file.
Configuration files are stored in var/config
.
As said before, each entry point may have its specific config file. Although in practice, many parameters can be shared between them. To prevent wasteful repeats defines a common config file : defaultconfig.ini.php
. Jelix automatically read its entries in addition to each config file related to an entry point. No need to tell jelix about it in an entry point.
Then, should lay in an entry point related config file, only specific parameters or overloaded parameters already defined in defaultconfig.ini.php
.
A glimpse at defaultconfig.ini.php
(abstract) :
locale = "fr_FR"
charset = "ISO-8859-1"
timeZone = "Europe/Paris"
theme = default
pluginsPath = lib:jelix-plugins/,app:plugins/
modulesPath = lib:jelix-modules/,app:modules/
[modules]
mymodule=2
jauth=2
[coordplugins]
;nom = nom_fichier_ini
[responses]
...
Example : a classic request with index.php as entry point should define var/config/index/config.ini.php
file. Storing under an index sub-directory serves only a better organization (As each entry point may have its config file, var/config
would quickly become a mess).
A specific config should only define or redefine a small amount of properties:
startModule = "testapp"
startAction = "main:index"
[coordplugins]
autolocale = index/autolocale.ini.php
[responses]
html=myHtmlResponse
take xmlrpc.php entry point, its config file could be :
startModule = "testapp"
startAction = "xmlrpc:index"
And so on for others entry points.
You have to know that a second defaultconfig.ini.php
exists into the lib/jelix/core/
directory. It contains all possible parameters and some comments. Jelix reads it first, then it read the defaultconfig.ini.php
of your application, and then it reads the configuration file of the entry point. Values of a configuration file override values of the previous configuration file.
The profiles.ini.php file ¶
This file contains all connections parameters of some Jelix Components: SQL and NoSQL databases, SOAP web services, cache etc. In Jelix 1.2 and lower, these parameters were stored in several files (dbProfils.ini.php, cache.ini.php...). Since Jelix 1.3, all is stored in an unique file.
This is an ini file. Each section correspond to a profile. A profile is a set of parameters of a single connection. Sections names are composed of two names, separated by a ":":
- first name is the name of the connection type, (often corresponding to the composant name)
- second name is a name of your choice. However two names have a special meaning: "default" indicates the default profile to use if the profile name is not given to the component. And "common", described below.
The content of the section content connection parameters.
Here is an example for a jDb connection (jDb allow to access to a SQL database):
[jdb:default]
driver=mysql
host=localhost
login= mylogin
password=mypassword
Profile Alias ¶
You can define some profile alias, ie more than one name to a profile. This is useful for example when a module uses a specific profile name, but it correspond to an existing profile in your configuration.
Aliases are defined in a section whose name contains only the name of the connection type. An example with jDb, defining the alias "jacl2_profile' for the default profile:
[jdb]
jacl2_profile = default
[jdb:default]
driver=mysql
host=localhost
login= mylogin
password=mypassword
An alias should not linked to an other alias.
Common parameters ¶
It is possible to define parameters that are common to all profiles of the same type. This avoids repeating them in each profile. To do this, you must declare them in a special profile, __common__
.
For example, if all connections to SQL databases (jDB) must be persistent and are all on the same server:
[jdb:__common__]
host=my.server.example.com
persistant=on
You can of course redefine these parameters in profiles.
Virtual profile ¶
You can use a profile which is not declared in profiles.ini.php
file. Then you can use a connection whose informations is known only during the execution.
A virtual profile must be created before using your component. Use createVirtualProfile
method of the object jProfiles
and pass it, the type name of connection, a name and an array of parameters.
Example
$params = array(
'driver'=>'mysql',
'host'=>'localhost',
'database'=>'jelix',
'user'=>'toto',
'password'=>'blabla',
'persistent'=>false,
'force_encoding'=>true
);
jProfiles::createVirtualProfile('jdb', 'my_profil', $params);
$cnx = jDb::getConnection('my_profil');
// and play with your database
Of course, all parameters defined in a __common__
profile apply on virtual profiles.