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 revisionBoth sides next revision
en:tutorials:minitutorial:1.0.3 [2008/04/06 09:50] laurenten:tutorials:minitutorial:1.0.3 [2008/04/06 10:41] laurent
Line 242: Line 242:
  
  
 +==== Template of an action ====
  
 +It should be more practical to put the content in a new template, dedicated to your action, for example in example/modules/example/templates/hello.tpl. So we have two templates: main.tpl which contains the main structure of the web site, and hello.tpl which specific to the action.
  
- +Let's create the hello.tpl in the templates directory:
-STOP HERE. tutorial not updated in the below content. +
- +
- +
- +
- +
- +
-==== The template ==== +
- +
-Create a hello.tpl file in the template directory of the module. And put in this content :+
  
 <code xml> <code xml>
-  <h2>Hello {$name} !</h2> +<div class="monbloc"> 
-  <p>Welcome in Jelix !</p> +<h2>Message</h2>
-</code> +
- +
-"{$name}" is a template variable : it will be replaced by the value you will define, like in this example : +
  
-<code php> +<div class="blockcontent">Hello {$name} !</div> 
-      $rep->body->assign('name','Me');+</div>
 </code> </code>
  
- +"{$name}" is variable template. Now modify the controller:
- +
-==== As summary ==== +
- +
-The code of the controller must now be like this :+
  
 <code php> <code php>
-class defaultCtrl extends jController { 
- 
    function index () {    function index () {
       $rep = $this->getResponse('html');       $rep = $this->getResponse('html');
       $rep->title = 'Hello World !';       $rep->title = 'Hello World !';
-       + 
-      $rep->bodyTpl = 'hello'; +      $tpl = new jTpl(); 
-      $rep->body->assign('name','Me');+      $tpl->assign('name','Me')
 +      $rep->body->assign('MAIN', $tpl->fetch('hello'));
          
       return $rep;       return $rep;
    }    }
-} 
 </code> </code>
  
  
 +Notice the use of the $tpl object. The "fetch" method generate the content of the given template. The 'hello' string is a selector of course.
  
-===== First display =====+You see now: 
 + 
 +{{en:tutorials:minitutorial:minituto_4_en.png}} 
 + 
 + 
 +STOP HERE. tutorial not updated in the below content.
  
-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 significant url to avoid all this disgusting parameters.  
  
 ===== Retrieving parameters ===== ===== Retrieving parameters =====
Line 304: Line 290:
 <code php> <code php>
    $name = $this->param('name');    $name = $this->param('name');
-   $rep->body->assign('name', $name);+   $tpl->assign('name', $name);
 </code> </code>
  
-Now type : +Now type: 
-    http://localhost/jelix/helloapp/www/index.php?module=hello&action=default:index&name=Robert+    http://localhost/jelix-1.0.3/app/www/index.php?name=Max
  
 +You will see:
 +
 +{{en:tutorials:minitutorial:minituto_5_en.png}}
 +
 +
 +===== URLs =====
 +
 +To execute a specific action, you should add in the url a "module" and an "action" parameter. For our example, we can type:
 +
 +   http://localhost/jelix-1.0/exemple/www/index.php?module=example&action=default:index
 +
 +The action parameter has the following syntax: controller_name:method_name
 +
 +However, in our example, this parameters are optional because the action has been defined as the default one in the web site. The default action is specified in the //example/var/config/index/config.ini.php// file, in //startModule// and //startAction// options:
 +
 +<code ini>
 +startModule="example"
 +startAction="default:index"
 +</code>
 +
 +You can change it later if you want.
 +
 +Well, this urls are not very friendly, and of course, you can change how URLS should look like. For example: http://localhost/index/news instead of  http://localhost/index?module=news&action=default:index. This is done by configuring the url engine. 
 +
 +You can also change the "DocumentRoot" of the web site and to set it to the  //jelix-1.0.3/exemple/www// directory, or move the content of the example/www to the root of your web site.
  
 ===== Conclusion ===== ===== Conclusion =====
  
-This were the first concepts of Jelix. You can continue to discover him by following the [[en:tutorials:main|main tutorial]].+ 
 +This were the first concepts of Jelix. You can continue to discover it by following the [[en:tutorials:main|main tutorial]].
  
 ----- -----

en/tutorials/minitutorial/1.0.3.txt · Last modified: 2008/11/19 15:02 by 127.0.0.1

Recent changes RSS feed Creative Commons License