Quick links: Content - sections - sub sections
EN

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
en:tutorial:action-creation [2006/09/22 15:03] doublefaceen:tutorial:action-creation [2006/09/26 16:12] doubleface
Line 1: Line 1:
 ====== Creation of an action ====== ====== Creation of an action ======
 +
  
 ===== A little bit of theory ===== ===== A little bit of theory =====
Line 12: 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 =====
 +
 +The actions are implemented in so-called controllers. Controllers are classes containing methods for each action. Controllers are placed in files :
 +controllers///controller_name//.//request_type//.php.
 +
 +In general, there is an index() method for the default action.
 +
 +Let's modifiy this default action. For this, open the contollers/default.classic.php. You should have this content:
 +
 +<code php>
 +class CTDefault extends jController {
 +
 +   function index () {
 +      $rep = $this->getResponse('html');
 +
 +      return $rep;
 +   }
 +}
 +</code>
 +
 +You see there are some naming conventions. Controller classes have a CT prefix, followed by the name of the controller (here: "default") indicated also in the action parameter, and the prefix of the file name *.classic.php. 
 +
 +There is an index() method, which retrieves the "html" type response.
 +
 +
 +
 +==== 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 <head> part of HTML, from some of its properties. For example, let's specify the title of the page :
 +
 +<code php>
 +   $rep->title = 'Last news';
 +</code>
 +
 +And the browser will receive :
 +
 +<code xml>
 +<head>
 +   <title>Last news</title>
 +</head>
 +</code>
 +
 +All the body of the page, i.e the content of the html tag <body>, must be generated by yourself, eventually through the Jelix tempplate engine : [[en:manual:templates|jTpl]]. jResponseHtml instantiates by default a template engine, in the body property. The name of the template file is placed in the bodyTpl property.
 +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>
 +  <h2>Last news</h2>
 +  <p>Section available soon.</p>
 +</code>
 +
 +As we said earlier, the content of the template will be the content of the <body> tag. That's why you don't have to give the <html>, <head>, ... tag. Only the content of the <body> tag.

en/tutorial/action-creation.txt · Last modified: 2007/09/17 22:42 by 127.0.0.1

Recent changes RSS feed Creative Commons License