Trace: • telechargement • 1.5 • jevent • 1.1.x
Differences ¶
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:tutorials:main:creating-action [2007/09/16 06:43] – created laurent | en:tutorials:main:creating-action [2012/04/15 08:32] (current) – laurent | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Creating an action ====== | ||
- | |||
- | |||
===== A little bit of theory ===== | ===== A little bit of theory ===== | ||
Line 8: | Line 5: | ||
An action is called through a request which has a defined type and generates a specific response, in a specific format, which can be linked to the type of the actual request. | An action is called through a request which has a defined type and generates a specific response, in a specific format, which can be linked to the type of the actual request. | ||
- | There are several types of requests, notably the type which is named “classic” in Jelix , for which an action can provide a response in an unspecified format: HTML, XML etc. It is for this type of request | + | There are several types of requests, notably the type which is named “classic” in Jelix , for which an action can provide a response in an unspecified format: HTML, XML etc. You will use generally |
- | You also have the xmlrpc type requests (used in web services). In XML-RPC, the input data are not URL parameters, but are stored in a XML content. As XML-RPC protocol wants it, an action defined for this type of request must obligatorily provide a response to XML-RPC format. | + | You have also the xmlrpc type requests (used for some web services). In XML-RPC, the input data are not URL parameters, but are stored in a XML content. As XML-RPC protocol wants it, an action defined for this type of request must obligatorily provide a response to XML-RPC format. |
Knowing the type of request processed and the action, Jelix knows the type of the answer to be generated, and thus controls more or less the response generation. Thus, even the error case (an exception or other) occurring during the processing of the action, the exit format will always be the awaited one. A client who calls a web service with xmlrpc, will thus have no matter what happens, a response in the xmlrpc format. That brings a certain robustness to the application. | Knowing the type of request processed and the action, Jelix knows the type of the answer to be generated, and thus controls more or less the response generation. Thus, even the error case (an exception or other) occurring during the processing of the action, the exit format will always be the awaited one. A client who calls a web service with xmlrpc, will thus have no matter what happens, a response in the xmlrpc format. That brings a certain robustness to the application. | ||
+ | |||
+ | Here is how Jelix work: | ||
+ | |||
+ | {{http:// | ||
+ | |||
+ | - an HTTP request calls Jelix. Jelix creates an instance of a jRequest object which contains datas of the request. It then create an instance of your controller which corresponds to the asked action. | ||
+ | - A method | ||
+ | - Then the method execute business processes, and retrieves eventually some results which will be used for the response | ||
+ | - The method of the controller create an instance of a jResponse object which is setup with datas or else (initialization of templates etc..). | ||
+ | - Jelix gets this jResponse object, launch the generation of the final document (html page, pdf..) and then send the result to the browser. | ||
Line 18: | Line 25: | ||
The actions are implemented in so-called controllers. Controllers are classes containing methods for each action. Controllers are placed in files : | The actions are implemented in so-called controllers. Controllers are classes containing methods for each action. Controllers are placed in files : | ||
- | controllers/// | ||
- | In general, there is an index() method for the default action. | + | controllers/// |
+ | |||
+ | In general, there is an //index()// method for the default action. | ||
- | Let' | + | Let' |
<code php> | <code php> | ||
Line 35: | Line 43: | ||
</ | </ | ||
- | You see there are some naming conventions. Controller classes have a name, here " | + | You see there are some naming conventions. Controller classes have a name, here " |
- | + | ||
- | + | ||
==== Response object ==== | ==== Response object ==== | ||
- | There is an index() method, we retrieve an " | + | In the //index()// method, we retrieve an " |
The jResponseHtml object handles the generation of a HTML response (ie an HTML page). It generates automatically the < | The jResponseHtml object handles the generation of a HTML response (ie an HTML page). It generates automatically the < | ||
Line 59: | Line 64: | ||
</ | </ | ||
- | All the body of the page, i.e the content of the html tag < | + | All the body of the page, i.e the content of the html tag < |
- | Before beginning to code, let's see the content of the template | + | |
+ | Before beginning to code, let's see the content of the template. | ||
==== The template ==== | ==== The template ==== | ||
- | Create a newslist.tpl file in the templates directory of the module. And place this content inside : | + | Create a //newslist.tpl// file in the //templates// directory of the module. And place this content inside |
<code xml> | <code xml> | ||
- | <h2>Last news</ | + | <h2>Lastest |
< | < | ||
</ | </ | ||
As we said earlier, the content of the template will be the content of the < | As we said earlier, the content of the template will be the content of the < | ||
- | |||
Line 92: | Line 97: | ||
</ | </ | ||
- | We the added an instruction to specify to the response that we use the newslist.tpl template. | + | We added an instruction to specify to the response that we use the newslist.tpl template. |
- | + | ||
- | A selector comprise a module name and a resource name separated by the " | + | |
- | + | ||
+ | A selector comprise a module name and a resource name separated by the " | ||
===== First display ===== | ===== First display ===== | ||
Line 103: | Line 105: | ||
We are now ready to display the first version of our action. For this, type the following url in your browser : | We are now ready to display the first version of our action. For this, type the following url in your browser : | ||
- | http:// | + | http:// |
You will then see the content of the template we created on the screen. | You will then see the content of the template we created on the screen. | ||
- | The action parameter is the name of the action to be executed. It is made from to parts, separated by an underscore | + | The action parameter is the name of the action to be executed. It is made from to parts, separated by a colon (in jelix 1.0b3.1 and prior, it was an underscore). The first part is the name of the controller, the second part is the name of the method to be executed. |
- | We can specify that this action will be the default action of the application. For this, open the configuration file actu.org/ | + | We can specify that this action will be the default action of the application. For this, open the configuration file news.org/ |
<code ini> | <code ini> | ||
- | defaultModule | + | startModule |
- | defaultAction | + | startAction |
</ | </ | ||
- | You can then use the following url : | + | You can then use the following url to display the " |
- | + | ||
- | http:// | + | |
- | + | ||
- | To display our first page. | + | |
+ | http:// | ||
- | ---- | ||
- | * Next : [[en: | ||
- | * Previous : [[en: | ||
- | * [[en: |