Quick links: Content - sections - sub sections
EN

Trace: jevent 1.4.x 1.2.x 1.3 1.4 1.2beta1 hall-of-fame principles 1.1.x 1.0

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.1.x [2009/01/07 20:18] biboen:tutorials:minitutorial:1.1.x [2012/04/15 08:36] (current) laurent
Line 6: Line 6:
 ===== Download and installation ===== ===== Download and installation =====
  
-First, [[en:download:stable:1.1#developer-edition|download the "developer" edition of Jelix]]. Jelix requires at least PHP 5.2 (See [[en:manual-1.1:installation:requirements|here a detailed list of requirements]])+First, [[en:download:stable:1.1#developer-edition|download the "developer" edition of Jelix]]. Jelix requires at least PHP 5.2 (See [[http://docs.jelix.org/en/manual-1.1/installation/requirements|here a detailed list of requirements]])
  
 Then, unpack the archive file you have downloaded, with your archiver software companion. For example, with tar: Then, unpack the archive file you have downloaded, with your archiver software companion. For example, with tar:
Line 118: Line 118:
 ===== Implementing an action ===== ===== Implementing an action =====
  
-Let's implement a default action. An action is a process which generates a page. It is implemented as a method in a class called a "controller", and a controller can implement several actions. Open the @@F@example/modules/example/controllers/default.classic.php@@ file:+Let's implement a default action. An action is a process which generates a page. It is implemented as a method in a class called a "controller". A controller can implement several actions.  
 + 
 +Open @@F@example/modules/example/controllers/default.classic.php@@ file:
  
 <code php> <code php>
Line 135: Line 137:
 </code> </code>
  
-We state here that we retrieve a @@C@jResponseHtml@@ object throw the @@M@getResponse()@@ method because of the "html" type as it is indicatedThen we return it to indicate that its content must be returned to the browser.+What this code means is that **index** action of **default** controller retrieves a @@C@jResponseHtml@@ object through the @@M@getResponse()@@ method by passing "html" as argumentAfter processing, the action returns this response thus indicating that its content must be returned to the browser.
  
  
-@@C@jResponseHtml@@ has a @@P@body@@ property, which is a @@C@jTpl@@ object. jTpl is a template engine provided by Jelix. In the controller, you see that the @@C@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 @@V@MAIN@@You will see what is a zone later. 'Check_install' zone is a zone which show the main content of the start pageAs we don't need it anymoredelete this line so you will have this in your controller:+@@C@jResponseHtml@@ has a @@P@body@@ property, which is a @@C@jTpl@@ object. jTpl is a template engine provided by Jelix.  
 + 
 +In the action code above, you see a call to @@C@assignZone()@@ method. This means : get the content of the 'check_install' zone which is stored in the 'jelix' module, and assign this content to the template variable named @@V@MAIN@@ (You will see what is a zone in details later). 'Check_install' is a zone which shows results of install checkingsIf those results are ok, you don't need it anymoredelete this line so you will have this in your controller:
  
 <code php> <code php>
Line 153: Line 157:
 ==== Response object ==== ==== Response object ====
  
-The @@C@jResponseHtml@@ object generates HTML response (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 @@M@index()@@ method, before the return:+@@C@jResponseHtml@@ object generates an HTML response (an HTML page). It automatically generates the @@<head>@@ part of HTML, from some of its properties.  
 + 
 +Let's define the title of the page. Add this in the @@M@index()@@ method, just before returning the response object :
  
 <code php> <code php>
Line 159: Line 165:
 </code> </code>
  
-Reload the page. The title of the page is now display in your browser title bar. But the page contains this:+Reload the page. The page title should now display accordingly in your browser title bar. But still your page contains this:
  
 {{en:tutorials:minitutorial:minituto_1_en.png}} {{en:tutorials:minitutorial:minituto_1_en.png}}
  
-How is this possible although we don'have anything in our controller ?+How is this possible whereas we don'define any content in our controller ?
  
-We saw that @@M@getResponse('html')@@ returns a @@C@jResponseHtml@@ object. However, it is possible to return an other object for the "html" type. It can be an other object which inherits from @@C@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 such class and a default template. This sort of classes are stored in the @@F@responses/@@ directory of the application, and are declared in the configuration file.+We have seen before that @@M@getResponse('html')@@ returns a @@C@jResponseHtml@@ object. However, it could return another object for the "html" type. It could be an instance of a class inheriting from @@C@jResponseHtml@@ and which set common things for all 'html' actions. Think about defining common CSS style sheets and JS scriptsyour application main template etc. This  class is very useful as you don't need to repeat this settings through all your actions. And because this is very useful, the @@createapp@@ command creates such class and a default template. it is stored in the @@F@responses/@@ directory of your application, and is declared in the configuration file.
  
 Let's see the content of @@F@example/responses/myHtmlResponse.class.php@@ created by @@createapp@@: Let's see the content of @@F@example/responses/myHtmlResponse.class.php@@ created by @@createapp@@:
Line 172: Line 178:
 class myHtmlResponse extends jResponseHtml { class myHtmlResponse extends jResponseHtml {
  
-    public $bodyTpl = 'exemple~main';+    public $bodyTpl = 'example~main';
  
     protected function doAfterActions() {     protected function doAfterActions() {
Line 180: Line 186:
 </code> </code>
  
-This "customized" response set up in @@P@bodyTpl@@ the default template which will be used to generate the @@<body>@@ content of all pages : "exemple~main". This is the @@F@main.tpl@@ file in the example module. "exemple~main" is called a selector. A [[en:manual-1.1:selectors|Jelix selector]] is a shortcut to refer to a resource of a module. Here is the content of this template:+This "customized" response assigns to its @@P@bodyTpl@@ member the default template which will be used to generate the @@<body>@@ content of all pages : "example~main". This is the @@F@main.tpl@@ file in the example module. "example~main" is called a selector. A [[http://docs.jelix.org/en/manual-1.1/selectors|Jelix selector]] is a shortcut to refer to a resource of a module. Here is the content of main.tpl:
  
 <code html> <code html>
-   <h1 class="apptitle">example<br/><span class="welcome">{@jelix~jelix.newapp.h1@}</span></h1>+   <h1 class="apptitle">Title for example<br/><span class="welcome">{@jelix~jelix.newapp.h1@}</span></h1>
    {$MAIN}    {$MAIN}
 </code> </code>
Line 189: Line 195:
 @@{$MAIN}@@ is an instruction which says: display the content of the template variable named @@V@MAIN@@. {@jelix~jelix.newapp.h1@} is an instruction which says: display the localized string (a string which value depends on the lang) identified by the "jelix.newapp.h1" key and stored in the "jelix" module. @@{$MAIN}@@ is an instruction which says: display the content of the template variable named @@V@MAIN@@. {@jelix~jelix.newapp.h1@} is an instruction which says: display the localized string (a string which value depends on the lang) identified by the "jelix.newapp.h1" key and stored in the "jelix" module.
  
-The method @@M@doAfterActions@@ is called after each action. In the example, it assigns @@"<p>no content</p>"@@ to the MAIN template variable if this variable doesn't exist yet  (so, if it is not set by the action).+@@M@doAfterActions@@ method is called after each action. In the example, it assigns @@"<p>no content</p>"@@ to the MAIN template variable if this variable doesn't exist yet  (so, if it is not set by the action).
  
 Now you know why there is a content displaying on the start page. Now let's modify the template with this content: Now you know why there is a content displaying on the start page. Now let's modify the template with this content:

en/tutorials/minitutorial/1.1.x.1231359487.txt.gz · Last modified: 2009/01/07 20:18 by bibo

Recent changes RSS feed Creative Commons License