|^ Core workflow||Application entry points and jApp »|
− Table of content
The usefulness of the selectors ¶
The selectors are used a lot in Jelix. They allow to indicate a resource, a file,
without having to know its path. Indeed, the tree structure of a Jelix
application can be modified according to standards of the server used (the
directory of the "myapp" application going in the
/var/lib/myapp/ for example, on a
In addition, the Jelix libs can be installed in another tree structure than the application.
Thus, the selectors make possible not to modify our application when it's differently installed.
And they avoid to type long file paths...
How a selector is defined ¶
A selector is a string with the following format:
"aModule~aResource", you can
forget the module when this is the module we are in. In this case, you can write
A selector indicates a precise type of resource. Here are the different types of selectors:
|file in var/||var||jSelectorVar|
|file in temp/||tmp||jSelectorTmp|
|file in lib/||lib||jSelectorLib|
In general, you will have to give a selector as parameter of certain methods without having to give its type. Indeed, these methods know this will be a selector on a precise type of resource.
Here, jDAO will look for a DAO file with the name myDAO.dao.xml in the myModule module.
Defining a precise type of selector ¶
The type can sometimes be different, or the method can take any type of
selector. In this case, you have to add a prefix to the selector, to specify its
type. This prefix is indicated in the above table. The notation of a selector is
This is called a "full selector".
We will then use the jSelectorFactory object to retrieve the corresponding selector object (see the class column in the table), and thus the physical path of the indicated resource.
$aSelector = "tpl:foo~bar"; ... $selector = jSelectorFactory::create($aSelector); // $selector will be an object of jSelectorTpl type $path_of_template = $selector->getPath();