Quick links: Content - sections - sub sections
EN FR

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 var/ directory of the "myapp" application going in the /var/lib/myapp/ for example, on a unix server).

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 "aRessource".

A selector indicates a precise type of resource. Here are the different types of selectors:

Resource Prefix Class
an action act jSelectorAct
a class class jSelectorClass
a locale loc jSelectorLoc
a dao dao jSelectorDao
a template tpl jSelectorTpl
a zone zone jSelectorZone
a plugin plug jSelectorPlugin
file in var/ var jSelectorVar
config file cfg jSelectorCfg
file in temp/ tmp jSelectorTmp
log file log jSelectorLog
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.


  jDAO::create("myModule~myDao");

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 then: "type:aModule~aResource".

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();