Section: Application entry points and jApp
« Selectors | ^ Core workflow | Request object » |
− Table of content
Entry points ¶
An entry point is a script which execute a part or all your application actions.
We can call them "boostrap" too.
Only entry points should be accessible from the web and therefore should lie in www/
directory of your application. It should exist an entry point for each type of request that
you want to use (normal, soap, xml-rpc ...). As a result, each entry point should also have
its specific configuration file.
An entry point initializes the jelix environment, creates a jCoordinator
object, a
jRequest
object (to parse all request parameters) and indicates which configuration
file to use. For a normal entry point (like index.php
), the code looks like this:
// application initialization file
require_once ('../../testapp/application.init.php');
// load the configuration file
jApp::loadConfig('index/config.ini.php');
// create the jCoordinator object and set it in the Jelix environment
jApp::setCoord(new jCoordinator());
// jRequest object
require_once (JELIX_LIB_CORE_PATH.'request/jClassicRequest.class.php');
$request = new jClassicRequest();
// action processing (routing, controller execution...)
jApp::coord()->process($request);
jApp ¶
As you can see, the entry point call a class, jApp
, which is initialized in the
application.init.php
file. This object contains only static methods.
This is a "central" object, because it contains informations about the runtime environment of the application. You will often use it in your modules.
This object contains first the configuration of the application (set with the loadConfig()
method),
and main objects used by Jelix components, such as the coordinator (set with the setCoord()
method).
You may call it in your class to access to all of this resources.
$config = jApp::config(); // to retrieve the object containing the current configuration
$coord = jApp::coord(); // to retrieve the coordinator, which contains many useful information
This object contains also all paths to different important directories of the application. You can retrieve them with these specific methods:
$path = jApp::appPath(); // the full path of the application directory
$path = jApp::varPath(); // the full path of the var directory of the application
$path = jApp::logPath(); // the full path of the log directory of the application (app/var/log)
$path = jApp::configPath(); // the full path of the config directory of the application (app/var/config)
$path = jApp::wwwPath(); // the full path of the web directory of the application (app/www)
$path = jApp::scriptsPath(); // the full path of the scripts directory of the application (app/scripts)
$path = jApp::tempPath(); // the full path of the temp directory corresponding to the entry point (temp/app/www/)
$modulePath = jApp::getModulePath('myModule'); // the full path to a module
You can give a filename to these methods (except getModulePath
), it will be append to the path.
It is highly recommended to use these methods instead of having hard coded path in your modules.