Quick links: Content - sections - sub sections
EN

Trace: nightly 1.3 creation-action 1.7.x utiliser-dao 1.7 1.3.x 1.1 1.0.3

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
en:tutorials:minitutorial:1.0.3 [2008/04/06 09:50] laurenten:tutorials:minitutorial:1.0.3 [2008/11/19 15:02] (current) – external edit 127.0.0.1
Line 157: Line 157:
 How is this possible although we don't have anything in our controller ? How is this possible although we don't have anything in our controller ?
  
-We saww that getResponse('html') returns a jResponseHtml object. However, it is possible to return an other object for the "html" type. It can be an other object which inherits from jResponseHtml, and which set things which are common for all actions. For example: CSS style sheets, the main template etc. This is very useful because you don't need to repeat this settings in your actions. And because this is very useful, the //createapp// command creates a such class and a default template. This sort of class are stored in the //responses// directory of the application, and are declared in the configuration file.+We sww that getResponse('html') returns a jResponseHtml object. However, it is possible to return an other object for the "html" type. It can be an other object which inherits from jResponseHtml, and which set things which are common for all actions. For example: CSS style sheets, the main template etc. This is very useful because you don't need to repeat this settings in your actions. And because this is very useful, the //createapp// command creates a such class and a default template. This sort of class are stored in the //responses// directory of the application, and are declared in the configuration file.
  
 Let's see the content of example/responses/myHtmlResponse.class.php created by //createapp//: Let's see the content of example/responses/myHtmlResponse.class.php created by //createapp//:
Line 172: Line 172:
 </code> </code>
  
-This "personnalized" response set up in bodyTpl the default template which will be used to generate the <body> content of all pages : "exemple~main". This is the main.tpl file in the example module. "exemple~main" is called a selector. A [[en:manual:selectors|Jelix selector]] is a shortcut to refer to a resource of a module. Here is the content of this template:+This "personnalized" response set up in bodyTpl the default template which will be used to generate the <body> content of all pages : "exemple~main". This is the main.tpl file in the example module. "exemple~main" is called a selector. A [[en:manual-1.0:selectors|Jelix selector]] is a shortcut to refer to a resource of a module. Here is the content of this template:
  
 <code html> <code html>
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 :  +<div class="blockcontent">Hello {$name} !</div
- +</div>
-<code php+
-      $rep->body->assign('name','Me');+
 </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:
  
-We are now ready to display our page. For this, give the following URL : +{{en:tutorials:minitutorial:minituto_4_en.png}}
-  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 284:
 <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.1207475451.txt.gz · Last modified: 2008/04/06 11:00 (external edit)

Recent changes RSS feed Creative Commons License