Quick links: Content - sections - sub sections

jApp is a class bringing informations about the Jelix environment.

It allows to specify (in application.init.php) and to retrieve, different path of the application.

It proposes also some methods to retrieve some global Jelix Object and to manipulate Jelix environment (internal use).

Access to some global objects

// the configuration object
$config = jApp::config();

//the router
$coord = jApp::coord();

There is also jApp::version() which allows to know the version of the application when there is a VERSION file in the application directory.

If you want to know the version of Jelix, you'll use jFramework::version().

Retrieving URL path to the application

To create URL, you'll often need the "basePath" value that is available into the configuration, and automatically calculated by the framework when you didn't specified it yourself. This method allow to retrieve easily this path:

$path = jApp::urlBasePath();
// old way to retrieve this path: jApp::config()->urlengine['basepath']

You can also retrieve the URL path to web assets provided by Jelix (from lib/jelix-www).

$path = jApp::urlJelixWWWPath();

Retrieving all miscellaneous physical path

jApp is configured during the startup of the application, in the file application.init.php. In particulary, path to different components of the application are set in it.

The method appPath() returns the full path of the application.

$path = jApp::appPath();

To have the path to the temp directory, call the method tempPath().

$path = jApp::tempPath();

Other path are available:

// the path to the var/ directory of the application
$path = jApp::varPath();

// the path to the var/log/ directory of the application
$path = jApp::logPath();

// the path to the app/system/ directory of the application
$path = jApp::appSystemPath();

// the path to the var/config/ directory of the application
$path = jApp::varConfigPath();
// The old method jApp::configPath() is also available but is deprecated

// the path to the www/ directory of the application
$path = jApp::wwwPath();

// the path to the scripts/ directory of the application
$path = jApp::scriptsPath();

You can give a sub-path or a file to these previous method, to have the full path.

You can also retrieve the path to the main configuration file of the application:

// the path to mainconfig.ini.php
$path = jApp::mainConfigFile();

You can retrieve the path to a specific module:

$path = jApp::getModulePath('my_module');

Configuring jApp

In the application.init.php file, you declare all different path of the application we saw above.

You do it with the initPaths() and setTempBasePath() methods:


This class contain also methods to indicate where Jelix can find modules and plugins:

// declare a list of directories containing modules
// declare a list of directories containing plugins

// declare the path to a module

Note that if you want to install Jelix and modules via Composer, these methods are called automatically with path of modules containing in packages. So in the example above, declaring jelix-modules and jelix-admin-modules is useless. It is only useful when you install jelix from a zip.

In the entry point, you have also to say what is the configuration file to use, and the router (coordinator) to use.

jApp::setCoord(new jCoordinator());

In case when the application.init.php is not in the main directory of the application (so, not into the directory having the project.xml file), you must call jApp::setApplicationInitFile(__FILE__) into the application.init.php file.