Quick links: Content - sections - sub sections
EN

Trace: 1.1 faq 1.2.2 1.7.x 1.4 1.1.x 1.6 minitutoriel community 1.7.x

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:main:creating-action [2007/11/30 13:44] laurenten:tutorials:main:creating-action [2012/04/15 08:32] (current) laurent
Line 1: Line 1:
-====== Creating an action ====== 
- 
- 
- 
 ===== A little bit of theory ===== ===== A little bit of theory =====
  
Line 21: Line 17:
   - an HTTP request calls Jelix. Jelix creates an instance of a jRequest object which contains datas of the request. It then create an instance of your controller which corresponds to the asked action.   - an HTTP request calls Jelix. Jelix creates an instance of a jRequest object which contains datas of the request. It then create an instance of your controller which corresponds to the asked action.
   - A method  in the controller is executed. It retrieves request parameters in order to know which process to run.   - A method  in the controller is executed. It retrieves request parameters in order to know which process to run.
-  - Then the method execute business processes, et retrieves eventually some results which will be used for the response+  - Then the method execute business processes, and retrieves eventually some results which will be used for the response
   - The method of the controller create an instance of a jResponse object which is setup with datas or else (initialization of templates etc..).   - The method of the controller create an instance of a jResponse object which is setup with datas or else (initialization of templates etc..).
-  - Jelix gets this jResponse object, launch the generation of the final document (html page, pdf..) and then send it to the browser.+  - Jelix gets this jResponse object, launch the generation of the final document (html page, pdf..) and then send the result to the browser.
  
  
Line 34: Line 30:
 In general, there is an //index()// method for the default action. In general, there is an //index()// method for the default action.
  
-Let'modifiy this default action. For this, open the contollers/default.classic.php. You should have this content:+Let'modify this default action. For this, open the contollers/default.classic.php. You should have this content:
  
 <code php> <code php>
Line 68: Line 64:
 </code> </code>
  
-All the body of the page, i.e the content of the html tag <body>, must be generated by yourself, eventually through the Jelix template engine : [[en:manual:templates|jTpl]]. jResponseHtml instantiates by default a template engine, in the **body** property. The name of the template file is placed in the **bodyTpl** property.+All the body of the page, i.e the content of the html tag <body>, must be generated by yourself, eventually through the Jelix template engine : [[http://docs.jelix.org/en/manual-1.0/templates|jTpl]]. jResponseHtml instantiates by default a template engine, in the **body** property. The name of the template file is placed in the **bodyTpl** property.
  
 Before beginning to code, let's see the content of the template. Before beginning to code, let's see the content of the template.
Line 101: Line 97:
 </code> </code>
  
-We added an instruction to specify to the response that we use the newslist.tpl template.  There is no need to type the ".tpl" suffix of the file name, because it is actually a Jelix [[en:manual:selectors|selector]]. A [[en:manual:selectors|selector]] is a string, allowing to easily indicate a resource of the project, independently of its physical place.+We added an instruction to specify to the response that we use the newslist.tpl template.  There is no need to type the ".tpl" suffix of the file name, because it is actually a Jelix [[http://docs.jelix.org/en/manual-1.0/selectors|selector]]. A [[http://docs.jelix.org/en/manual-1.0/selectors|selector]] is a string, allowing to easily indicate a resource of the project, independently of its physical place.
  
-A selector comprise a module name and a resource name separated by the "~" character, like this: "module_name~resource_name". The "module_name~" part is not mandatory when this is the current module. The resource name is not obligatorily a file name, even if, most of the time, it is a file name. The object which uses the selector ([[en:manual:templates|jTpl]] here) knows how to retrieve the file corresponding to the selector. You will see that the selectors are very often used and allow a certain flexibility and independence from physical paths.+A selector comprise a module name and a resource name separated by the "~" character, like this: "module_name~resource_name". The "module_name~" part is not mandatory when this is the current module. The resource name is not obligatorily a file name, even if, most of the time, it is a file name. The object which uses the selector ([[http://docs.jelix.org/en/manual-1.0/templates|jTpl]] here) knows how to retrieve the file corresponding to the selector. You will see that the selectors are very often used and allow a certain flexibility and independence from physical paths.
  
 ===== First  display ===== ===== First  display =====
Line 109: Line 105:
 We are now ready to display the first version of our action. For this, type the following url in your browser : We are now ready to display the first version of our action. For this, type the following url in your browser :
  
-  http://localhost/jelix/news.org/www/index.php?module=news&action=default_index+  http://localhost/jelix/news.org/www/index.php?module=news&action=default:index
  
 You will then see the content of the template we created on the screen. You will then see the content of the template we created on the screen.
  
-The action parameter is the name of the action to be executed. It is made from to parts, separated by an underscore (_). The first part is the name of the controller, the second part is the name of the method to be executed.+The action parameter is the name of the action to be executed. It is made from to parts, separated by a colon (in jelix 1.0b3.1 and prior, it was an underscore). The first part is the name of the controller, the second part is the name of the method to be executed.
  
 We can specify that this action will be the default action of the application. For this, open the configuration file news.org/var/config/index/config.ini.php and specify it : We can specify that this action will be the default action of the application. For this, open the configuration file news.org/var/config/index/config.ini.php and specify it :
Line 119: Line 115:
 <code ini> <code ini>
 startModule = "news" startModule = "news"
-startAction = "default_index"+startAction = "default:index"
 </code> </code>
  
Line 126: Line 122:
   http://localhost/jelix/news.org/www/index.php   http://localhost/jelix/news.org/www/index.php
  
- 
----- 
-   * Next : [[en:tutorials:main:database-config|Configuration of the database]] 
-   * Previous : [[en:tutorials:main:creating-application|Application creation]] 
-   * [[en:tutorials:main|Back to the summary]] 

en/tutorials/main/creating-action.1196430282.txt.gz · Last modified: 2007/12/18 11:19 (external edit)

Recent changes RSS feed Creative Commons License