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:tutorials:minitutorial:1.0.3 [2008/04/06 09:17] laurenten:tutorials:minitutorial:1.0.3 [2008/04/06 09:50] laurent
Line 97: Line 97:
 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.
  
  
Line 143: Line 145:
 ==== 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 149: 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