Trace:
Differences ¶
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
en:tutorial:action-creation [2006/09/25 08:39] – doubleface | en:tutorial:action-creation [2006/11/08 11:05] – (old revision restored) 127.0.0.1 | ||
---|---|---|---|
Line 13: | Line 13: | ||
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. | ||
+ | |||
===== Implementing an action ===== | ===== Implementing an action ===== | ||
Line 39: | Line 40: | ||
+ | |||
+ | ==== Response object ==== | ||
+ | |||
+ | In the $rep variable, you get an object extending the jResponse class. Since we specified, that the response is the HTML type, you actually get a jResponse Html object (extending jResponse). You will see later that there are other types of responses, and that you can produce your own response objects. | ||
+ | |||
+ | The jResponseHtml object handles the generation of a HTML response (ie an HTML page). It generates automatically the < | ||
+ | |||
+ | <code php> | ||
+ | | ||
+ | </ | ||
+ | |||
+ | And the browser will receive : | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | 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 | ||
+ | |||
+ | |||
+ | |||
+ | ==== The template ==== | ||
+ | |||
+ | Create a newslist.tpl file in the templates directory of the module. And place this content inside : | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | As we said earlier, the content of the template will be the content of the < | ||
+ | |||
+ | |||
+ | |||
+ | ==== Using the template in the action ==== | ||
+ | |||
+ | Let's see what we now have in the controller : | ||
+ | |||
+ | <code php> | ||
+ | class CTDefault extends jController { | ||
+ | |||
+ | | ||
+ | $rep = $this-> | ||
+ | $rep-> | ||
+ | $rep-> | ||
+ | return $rep; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | We the added an instruction to specify to the response that we use the newslist.tpl template. | ||
+ | |||
+ | A [[en: | ||
+ | |||
+ | |||
+ | |||
+ | ===== First display ===== | ||
+ | |||
+ | We are now ready to display the first version of our action. For this, type the following url in your browser : | ||
+ | |||
+ | http:// | ||
+ | |||
+ | 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 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/ | ||
+ | |||
+ | <code ini> | ||
+ | defaultModule = " | ||
+ | defaultAction = " | ||
+ | </ | ||
+ | |||
+ | You can then use the following url : | ||
+ | |||
+ | http:// | ||
+ | |||
+ | To display our first page. | ||
+ | |||
+ | |||
+ | ---- | ||
+ | * Next : [[en: | ||
+ | * Previous : [[en: | ||
+ | * [[en: |