Trace:
Differences ¶
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:tutorials:minitutorial [2007/12/18 09:31] – laurent | en:tutorials:minitutorial [2024/04/27 20:43] (current) – [Mini Tutorial] laurent | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~LANG: | ||
+ | |||
====== Mini Tutorial ====== | ====== Mini Tutorial ====== | ||
- | The goal of this tutorial is to quickly show you how you can develop an application. To start, install Jelix as indicated on the [[en:manual:installation|installation]] page. We will consider that you are using the default configuration, | + | * [[en:tutorials:minitutorial: |
- | ===== Jelix scripts ===== | + | For old jelix version which are unmaintained: |
- | A script | + | * [[en: |
+ | * [[en: | ||
+ | * [[en:tutorials: | ||
+ | * [[en: | ||
+ | * [[en: | ||
+ | * [[en: | ||
+ | * [[en: | ||
- | <code bash> | ||
- | cd lib/ | ||
- | cd lib\jelix-scripts\ | ||
- | </ | ||
- | |||
- | You have to use jelix.php with the command line version of PHP and give it as parameter a Jelix command with some other parameters and options. | ||
- | |||
- | <code bash> | ||
- | php jelix.php [--application_name] command_name [options] [parameters] | ||
- | </ | ||
- | |||
- | To avoid giving the name of the application for each command, execute this command line : | ||
- | |||
- | <code bash> | ||
- | export JELIX_APP_NAME=helloapp | ||
- | set JELIX_APP_NAME=helloapp | ||
- | </ | ||
- | |||
- | Then we will create an application named " | ||
- | |||
- | ===== Creation of an application ===== | ||
- | |||
- | Let's create the tree structure of the application using the createapp command : | ||
- | |||
- | <code bash> | ||
- | php jelix.php createapp | ||
- | </ | ||
- | |||
- | You will then get a helloapp/ directory, at the same level as the lib/ directory. Its content is the following : | ||
- | |||
- | helloapp/ | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | |||
- | ===== Creation of a module ===== | ||
- | |||
- | A module gathers a whole of actions. At least one is necessary in an application. Let's create our first module " | ||
- | |||
- | <code bash> | ||
- | php jelix.php createmodule hello | ||
- | </ | ||
- | |||
- | Here is the directory which has been created : | ||
- | |||
- | | ||
- | hello/ | ||
- | module.xml | ||
- | controllers/ | ||
- | | ||
- | classes/ | ||
- | daos/ the object-relational mapping files | ||
- | locales/ | ||
- | en_EN/ | ||
- | fr_FR/ | ||
- | templates/ | ||
- | zones/ | ||
- | |||
- | ===== Action implementation ===== | ||
- | |||
- | Let's implement a default action. Open the controllers/ | ||
- | |||
- | <code php> | ||
- | class defaultCtrl extends jController { | ||
- | |||
- | | ||
- | $rep = $this-> | ||
- | |||
- | return $rep; | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | 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 ==== | ||
- | |||
- | The jResponseHtml object generates a HTML response (a HTML page). It generates automatically the < | ||
- | |||
- | <code php> | ||
- | | ||
- | </ | ||
- | |||
- | The body of the page is generated by default from a template, via an instance of the Jelix template engine, placed in the **body** property. The name of the template file is placed in the **bodyTpl** property. Here, it's the hello.tpl file. | ||
- | |||
- | <code php> | ||
- | $rep-> | ||
- | </ | ||
- | |||
- | We don't put the " | ||
- | |||
- | Note that you can create your own response objects (possibly deriving from the class jResponseHtml), | ||
- | |||
- | ==== The template ==== | ||
- | |||
- | Create a hello.tpl file in the template directory of the module. And put in this content : | ||
- | |||
- | <code xml> | ||
- | < | ||
- | < | ||
- | </ | ||
- | |||
- | " | ||
- | |||
- | <code php> | ||
- | $rep-> | ||
- | </ | ||
- | |||
- | |||
- | |||
- | ==== As a summary ==== | ||
- | |||
- | The code of the controller must now be like this : | ||
- | |||
- | <code php> | ||
- | class defaultCtrl extends jController { | ||
- | |||
- | | ||
- | $rep = $this-> | ||
- | $rep-> | ||
- | | ||
- | $rep-> | ||
- | $rep-> | ||
- | | ||
- | return $rep; | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | |||
- | |||
- | ===== First display ===== | ||
- | |||
- | We are now ready to display our page. For this, give the following URL : | ||
- | http:// | ||
- | |||
- | You will then see your html page, with the welcome message. | ||
- | |||
- | The url can change regarding the configuration of your installation, | ||
- | |||
- | ===== Retrieving parameters ===== | ||
- | |||
- | It would be interesting to be able to indicate the name to display in the template, as a parameter of the url. We get a parameter value with //param()// method : | ||
- | |||
- | <code php> | ||
- | $name = $this-> | ||
- | | ||
- | </ | ||
- | |||
- | Now type : | ||
- | http:// | ||
- | |||
- | |||
- | ===== Conclusion ===== | ||
- | |||
- | This were the first concepts of Jelix. You can continue to discover him by following the [[en: | ||
----- | ----- | ||
* Go back to the [[en: | * Go back to the [[en: | ||
- | * Continue to discover Jelix with the [[en: | + | |