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:minitutorial [2006/09/14 16:03] doublefaceen:minitutorial [2006/11/08 11:04] – (old revision restored) 127.0.0.1
Line 45: Line 45:
      var/overloads/ will contain the different files that will have redefined, from other modules.       var/overloads/ will contain the different files that will have redefined, from other modules. 
      www/           the root of the site      www/           the root of the site
 +
  
  
Line 69: Line 70:
                 templates/          templates of the module                 templates/          templates of the module
                 zones/              objects processing specific zones in a page                 zones/              objects processing specific zones in a page
 +
 +
 +
 +===== Action implementation =====
 +
 +Let's implement a default action. Open the controllers/default.classic.php file and modify the content this way :
 +
 +<code php>
 +class CTDefault extends jController {
 +
 +   function index () {
 +      $rep = $this->getResponse('html');
 +
 +      return $rep;
 +   }
 +}
 +</code>
 +
 +We state here that we retrieve the jResponseHtml object (because of the HTML type as it is indicated), and we return it to indicate that its content must be returned to the browser.
 +
 +
 +
 +
 +==== Response object ====
 +
 +The jResponseHtml object generates a response in HTML (a HTML page). It generates automatically the <head> part of HTML, from some of its properties. Let's define the title of the page :
 +
 +<code php>
 +   $rep->title = 'Hello World !';
 +</code>
 +
 +The body of the page is generated by default by a template, via an instance of the Jelix template engine, placed in the body property. The name of the template file is placed in the bodyTpl property. Here, it's the hello.tpl file.
 +
 +<code php>
 +      $rep->bodyTpl = 'hello';
 +</code>
 +
 +We don't put the ".tpl" part because the content of the string is actually a Jelix //selector//. A Jelix selector is a link made to be able to refer to a resource of a module.
 +
 +
 +==== The template ====
 +
 +Create a hello.tpl file in the template directory of the module. And put in this content :
 +
 +<code xml>
 +  <h2>Hello {$name} !</h2>
 +  <p>Welcome in Jelix !</p>
 +</code>
 +
 +"{$name}" is a template variable : it will be replaced by the value you will define, like in this example : 
 +
 +<code php>
 +      $rep->body->assign('name','Me');
 +</code>
 +
 +
 +
 +==== As a summary ====
 +The code of the controller must now be like this :
 +
 +<code php>
 +class CTDefault extends jController {
 +
 +   function index () {
 +      $rep = $this->getResponse('html');
 +      $rep->title = 'Hello World !';
 +      
 +      $rep->bodyTpl = 'hello';
 +      $rep->body->assign('name','Me');
 +    
 +      return $rep;
 +   }
 +}
 +</code>
 +
 +
 +
 +===== First display =====
 +
 +We are now ready to display our page. For this, give the following URL :
 +  http://localhost/jelix/helloapp/www/index.php?module=hello&action=default_index
 +
 +You will then see your html page, with the welcome message.
 +
 +The url can change regarding the configuration of your installation, especially if you have specified the document root of the site on the directory helloapp/www. You have to know that Jelix can handle the significant url to avoid all this disgusting parameters. 
 +
 +
 +
 +===== Retrieving parameters =====
 +
 +It would be interesting to be able to indicate as parameter of the url, the name to display in the template.
 +
 +<code php>
 +   $name = $this->param('name');
 +   $rep->body->assign('name', $name);
 +</code>
 +
 +Now type :
 +    http://localhost/jelix/helloapp/www/index.php?module=hello&action=default_index&name=Robert
 +
 +-----
 +   * Go back to the [[en:manual|manual]]
 +   * Continue to discover Jelix with the [[en:tutorial|main tutorial]]
  
Recent changes RSS feed Creative Commons License