Quick links: Content - sections - sub sections
EN FR

URLs: identifying an action

Once you have created a controller, you can call one of its public method. So you have to indicate the needed information in the urls.

There is a mapping between an URL and an action (module/controller/method). All mapping is stored into the app/system/urls.xml file.

If an url is not indicated to a specific action into urls.xml then to access to the action is made with an url like that:


   index.php/mymodule/mycontroller/mymethod

Each element of this url are optional. These urls are valid:


   index.php/mymodule/mycontroller
   index.php/mymodule
   index.php

Note that the name of the controller and the method should be separated by the ":" character.

  • If the name of the method is not in the URL, the method index() of the controller will be called.
  • If the name of the controller is not in the URL (and obviously not the method name), jelix try to execute the method index() of the controller default.
  • If the module is missing in the URL, jelix call the module and the action corresponding to the URL "/". "/" is the only one URL that is required into the urls.xml file.

Action selectors

In your templates and in your code in general, you should never use "hard coded" url. Jelix includes a mechanism (the jUrl class) to generate the urls corresponding to actions. This allows you to changes the mapping between urls and actions, without modifying templates or controllers.

So the most of the time, you will have to indicate some action selectors (plus eventually some parameters) to various objects or methods of the Jelix API. See the page on the selectors for more information about them in general.

The actions selectors have this syntax:


    module~controller:method

You may omit one of these parties, as previously specified:


   controller:method
   method
   module~
   controller:

You can also specify the "#" character to specify the current module or the current action. In these examples, let's say that the action is "bar:man" of the module "foo" which has been called in jelix:

  • "#~controller:method" represents the action "controller:method" of the current module which has been called, so it is equivalent to "foo~controller:method".
  • "module~#" represents the action which has been called but in the indicated module, this equals to "module~bar:man".
  • "#~#" Represents the module and the action which has been called, so it equals to "foo~bar:man".

Indicating the entry point

By default, when you use an action selector, it generates the url with the current entry point: if we call the application with index.php, it will be index.php. If it is called with xmlrpc.php, it will be xmlrpc.php.

However, we would want to indicate the urls for other entry points: for example, we are in an action which displays an HTML page, and we want to indicate the URL of the entry point for jsonrpc Web services.

In this case, we should add at the end of the action selector, a "@" followed by the name of the type of the entry. Here is an example:


   foo~bar:man@jsonrpc

Here we ask the url of the action "bar:man" in the module "foo", for queries of "jsonrpc" type.

For most of urls, and especially for all actions which are accessible from the index.php file, the type is "@classic."

If in an action selector, we just indicate the type of request, it refers to the module and the action indicated for the URL "/" into the configuration. To know more, read configuration and use of urls in Jelix.