Trace:
Differences ¶
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
en:tutorials:minitutorial:1.0.3 [2008/04/06 09:17] – laurent | en:tutorials:minitutorial:1.0.3 [2008/04/06 10:50] – laurent | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Mini Tutorial ====== | ||
- | |||
- | The goal of this tutorial is to quickly show you how you can develop an application with Jelix 1.0.3. | ||
- | |||
- | If you have downloaded Jelix 1.0.2 or less, [[en: | ||
- | |||
- | |||
- | ===== Download and installation ===== | ||
- | |||
- | First, [[en: | ||
- | |||
- | Unarchive then the file you have downloaded, with your uncompress software. For example, with tar: | ||
- | |||
- | tar xvzf jelix-1.0.3-dev.tar.gz | ||
- | |||
- | After this, you have a directory jelix-1.0.3/ | ||
- | |||
- | For this tutorial, move the jelix-1.0.3 directory in the directory of your web site, so it will be accessible throw a browser, at this URL for example: http:// | ||
- | |||
- | ===== Jelix scripts ===== | ||
- | |||
- | A script for command line, jelix.php, is available in the lib/ | ||
- | |||
- | <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] | ||
- | </ | ||
- | |||
- | |||
- | ===== Creation of an application ===== | ||
- | |||
- | Let's create the tree structure of the application using the createapp command. Our application will be named " | ||
- | |||
- | <code bash> | ||
- | php jelix.php --example createapp | ||
- | </ | ||
- | |||
- | You will then get a example/ directory, at the same level as the lib/ directory. Its content is the following : | ||
- | |||
- | example/ | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | |||
- | |||
- | ===== Creation of a module ===== | ||
- | |||
- | A module gathers a whole of actions. At least one is necessary in an application. This is why a module is created automatically when you run // | ||
- | |||
- | Here is the directory which has been created: | ||
- | |||
- | | ||
- | example/ | ||
- | module.xml | ||
- | controllers/ | ||
- | | ||
- | classes/ | ||
- | daos/ the object-relational mapping files | ||
- | forms/ | ||
- | locales/ | ||
- | en_EN/ | ||
- | fr_FR/ | ||
- | templates/ | ||
- | zones/ | ||
- | |||
- | |||
- | If you want to create other modules later, you can use the // | ||
- | <code bash> | ||
- | php jelix.php --example createmodule cms | ||
- | </ | ||
- | |||
- | It will create a module named " | ||
- | |||
- | |||
- | ===== First display ===== | ||
- | |||
- | Before to display the start page of your new application, | ||
- | |||
- | For example, on linux (ubuntu or debian) : | ||
- | |||
- | <code bash> | ||
- | sudo chown www-data: | ||
- | sudo chmod 755 ../ | ||
- | </ | ||
- | |||
- | We are now ready to display the page. Your application is accessible at this URL: http:// | ||
- | |||
- | |||
- | You notice this message saying that a CSS file is missing. Copy the jelix-1.0.3/ | ||
- | |||
- | Now you should see: | ||
- | |||
- | |||
- | It there are some error messages in " | ||
- | |||
- | |||
- | ===== 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 " | ||
- | |||
- | <code php> | ||
- | class defaultCtrl extends jController { | ||
- | |||
- | | ||
- | $rep = $this-> | ||
- | |||
- | // this is a call for the ' | ||
- | // remove this line ! | ||
- | | ||
- | |||
- | | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | We state here that we retrieve a jResponseHtml object throw the // | ||
- | |||
- | |||
- | jResponseHtml has a " | ||
- | |||
- | <code php> | ||
- | class defaultCtrl extends jController { | ||
- | |||
- | | ||
- | $rep = $this-> | ||
- | |||
- | | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | ==== 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: | ||
- | * Continue to discover Jelix with the [[en: | ||