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

Next revision
Previous revision
Next revisionBoth sides next revision
en:tutorials:minitutorial:1.0.3 [2008/04/03 22:50] – created laurenten:tutorials:minitutorial:1.0.3 [2008/04/06 09:50] laurent
Line 30: Line 30:
  
 <code bash> <code bash>
-php jelix.php [--application_namecommand_name [options] [parameters]+php jelix.php --application_name command_name [options] [parameters]
 </code> </code>
  
Line 50: Line 50:
      var/log/       the log files      var/log/       the log files
      var/themes/    the different possible themes in your application      var/themes/    the different possible themes in your application
-     var/overloads/  will contain the different files that you will redefine, from other modules. +     var/overloads/  will contain the different files that you will redefine, from modules. 
      www/           the root of the site      www/           the root of the site
  
Line 91: Line 91:
  
 <code bash> <code bash>
-   chown www-data:www-data ../../temp/exemple ../../exemple/var/log +   sudo chown www-data:www-data ../../temp/example ../../example/var/log 
-   chmod 755 ../../temp/exemple ../../exemple/var/log+   sudo chmod 755 ../../temp/example ../../example/var/log
 </code> </code>
  
 We are now ready to display the page. Your application is accessible at this URL: http://localhost/jelix-1.0.3/example/www/. Enter this URL in your browser. you should see: We are now ready to display the page. Your application is accessible at this URL: http://localhost/jelix-1.0.3/example/www/. Enter this URL in your browser. you should see:
  
 +{{en:tutorials:minitutorial:start_page_white_en.png}}
  
 You notice this message saying that a CSS file is missing. Copy the jelix-1.0.3/lib/jelix-www  directory in dans jelix-1.0.3/example/www  by renaming it to "jelix" (on a dedicated apache server, it is better to create an alias). This directory is important because it contains some files needed by jForms or other components. You notice this message saying that a CSS file is missing. Copy the jelix-1.0.3/lib/jelix-www  directory in dans jelix-1.0.3/example/www  by renaming it to "jelix" (on a dedicated apache server, it is better to create an alias). This directory is important because it contains some files needed by jForms or other components.
Line 102: Line 103:
 Now you should see: Now you should see:
  
 +{{en:tutorials:minitutorial:start_page_en.png}}
  
-It there are some error messages in "installation check", fix them.+If there are some error messages in "installation check", fix them.
  
  
 +===== Implementing an action =====
  
-STOP HEREtutorials not still updated for Jelix 1.0.3+Let's implement a default actionAn action is a process which generates a pageIt is implemented as a method in a class called a "controller", and a controller can implement several actionsOpen the //example/modules/example/controllers/default.classic.php// file:
  
 +<code php>
 +class defaultCtrl extends jController {
  
 +   function index () {
 +       $rep = $this->getResponse('html');
  
 +       // this is a call for the 'welcome' zone after creating a new application
 +       // remove this line !
 +       $rep->body->assignZone('MAIN', 'jelix~check_install');
  
 +       return $rep;
 +   }
 +}
 +</code>
  
-===== Action implementation =====+We state here that we retrieve a jResponseHtml object throw the //getResponse// method because of the "html" type as it is indicated. Then we return it to indicate that its content must be returned to the browser.
  
-Let's implement default actionOpen the controllers/default.classic.php file and modify the content this way :+ 
 +jResponseHtml has "body" property, which is a jTpl objectjTpl is a template engine provided by Jelix. In the controller, you see that the assignZone method is calledIt says: get the content of the 'check_install' zone which is stored in the 'jelix' module, and put this content into the template variable named "MAIN". You will see what is a zone later. 'Check_install' zone is a zone which show the main content of the start page. As we don't need it anymore, delete this line so you will have this in your controller:
  
 <code php> <code php>
Line 121: Line 136:
  
    function index () {    function index () {
-      $rep = $this->getResponse('html');+       $rep = $this->getResponse('html');
  
-      return $rep;+       return $rep;
    }    }
 } }
 </code> </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 ==== ==== Response object ====
  
-The jResponseHtml object generates a HTML response (a HTML page). It generates automatically the <head> part of HTML, from some of its properties. Let's define the title of the page :+The jResponseHtml object generates a HTML response (a HTML page). It generates automatically the <head> part of HTML, from some of its properties. Let's define the title of the page. Add this in the //index// method, before the return:
  
 <code php> <code php>
Line 139: Line 151:
 </code> </code>
  
-The body of the page is generated by default from templatevia an instance of the Jelix template engineplaced in the **body** propertyThe name of the template file is placed in the **bodyTpl** propertyHereit's the hello.tpl file.+Reload the page. The title of the page is now display in your browser title bar. But the page contains this: 
 + 
 +{{en:tutorials:minitutorial:minituto_1_en.png}} 
 + 
 +How is this possible although we don't have anything in our controller ? 
 + 
 +We saww that getResponse('html') returns jResponseHtml object. Howeverit is possible to return an other object for the "html" type. It can be an other object which inherits from jResponseHtmland which set things which are common for all actionsFor 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 templateThis sort of class are stored in the //responses// directory of the applicationand are declared in the configuration file. 
 + 
 +Let'see the content of example/responses/myHtmlResponse.class.php created by //createapp//:
  
 <code php> <code php>
-      $rep->bodyTpl = 'hello';+class myHtmlResponse extends jResponseHtml { 
 + 
 +    public $bodyTpl = 'exemple~main'; 
 + 
 +    protected function _commonProcess() { 
 +        $this->body->assignIfNone('MAIN','<p>no content</p>'); 
 +    } 
 +}
 </code> </code>
  
-We don't put the ".tplpart because the content of the string is actually Jelix //selector//. A Jelix selector is a shortcut to refer to a resource of a module.+This "personnalizedresponse 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: 
 + 
 +<code html> 
 +   <h1 class="apptitle">example<br/><span class="welcome">{@jelix~jelix.newapp.h1@}</span></h1> 
 +   {$MAIN} 
 +</code> 
 + 
 +//{$MAIN}// is an instruction which says: display the content of the template variable named "MAIN". //{@jelix~jelix.newapp.h1@}// is an instruction which says: display the localized string (a string dependings of the lang) identified by tge "jelix.newapp.h1" key and stored in the "jelix" module. 
 + 
 +The method "_commonProcess" is called after each actions. In the example, it assign "<p>no content</p>" to the MAIN template variable if this variable doesn't still exists (so, if it is not set by the action). 
 + 
 +Now you know why there is a content displays on the start page. Now let's modify the template with this content: 
 + 
 +<code html> 
 +<h1 class="apptitle">My web site</h1> 
 + 
 +<div id="page"> 
 +{$MAIN} 
 +</div> 
 +</code> 
 + 
 +And in the constructor of the _commonProcess method, we add an instruction to setup a CSS style sheet: 
 + 
 +<code php> 
 + 
 +class myHtmlResponse extends jResponseHtml { 
 + 
 +    public $bodyTpl = 'example~main'; 
 + 
 +    public function __construct() { 
 +        parent::__construct(); 
 +        global $gJConfig; 
 +        $this->addCSSLink($gJConfig->urlengine['jelixWWWPath'].'design/jelix.css'); 
 + 
 +    } 
 + 
 +    protected function _commonProcess() { 
 +        $this->body->assignIfNone('MAIN','<p>no content</p>'); 
 +    } 
 +
 + 
 +</code> 
 + 
 +Now you see: 
 + 
 +{{en:tutorials:minitutorial:minituto_2_en.png}} 
 + 
 +==== Your first content ==== 
 + 
 +Let's define the content of our start page: 
 + 
 +<code php> 
 +class defaultCtrl extends jController { 
 + 
 +   function index () { 
 +      $rep = $this->getResponse('html'); 
 +      $rep->title = 'Hello World !'; 
 +       
 +      $rep->body->assign('MAIN',"<p>Hello !</p>"); 
 +     
 +      return $rep; 
 +   } 
 +
 +</code> 
 + 
 +So here, we put "<p>Hello !</p>" in the "MAIN" template variable. We now see: 
 + 
 +{{en:tutorials:minitutorial:minituto_3_en.png}} 
 + 
 + 
 + 
 + 
 + 
 +STOP HERE. tutorial not updated in the below content. 
 + 
 + 
  
-Note that you can create your own response objects (possibly deriving from the class jResponseHtml), and so to put at it all common process to several or all your actions, so this process will not have to be duplicate in each action (like the name of the template, the inclusion of common zones etc.). 
  
 ==== The template ==== ==== The template ====

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