Trace:
Differences ¶
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:tutorials:minitutorial [2008/04/06 11:46] – external edit 127.0.0.1 | 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 with Jelix 1.0.3. | + | * [[en: |
| - | If you have downloaded Jelix 1.0.2 or less, [[en:tutorials: | + | For old jelix version which are unmaintained: |
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[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:// | ||
| - | |||
| - | {{en: | ||
| - | |||
| - | You notice this message saying that a CSS file is missing. Copy the jelix-1.0.3/ | ||
| - | |||
| - | Now you should see: | ||
| - | |||
| - | {{en: | ||
| - | |||
| - | If 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> | ||
| - | | ||
| - | </ | ||
| - | |||
| - | Reload the page. The title of the page is now display in your browser title bar. But the page contains this: | ||
| - | |||
| - | {{en: | ||
| - | |||
| - | How is this possible although we don't have anything in our controller ? | ||
| - | |||
| - | We sww that getResponse(' | ||
| - | |||
| - | Let's see the content of example/ | ||
| - | |||
| - | <code php> | ||
| - | class myHtmlResponse extends jResponseHtml { | ||
| - | |||
| - | public $bodyTpl = ' | ||
| - | |||
| - | protected function _commonProcess() { | ||
| - | $this-> | ||
| - | } | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | This " | ||
| - | |||
| - | <code html> | ||
| - | < | ||
| - | | ||
| - | </ | ||
| - | |||
| - | //{$MAIN}// is an instruction which says: display the content of the template variable named " | ||
| - | |||
| - | The method " | ||
| - | |||
| - | 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=" | ||
| - | |||
| - | <div id=" | ||
| - | {$MAIN} | ||
| - | </ | ||
| - | </ | ||
| - | |||
| - | 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 = ' | ||
| - | |||
| - | public function __construct() { | ||
| - | parent:: | ||
| - | global $gJConfig; | ||
| - | $this-> | ||
| - | |||
| - | } | ||
| - | |||
| - | protected function _commonProcess() { | ||
| - | $this-> | ||
| - | } | ||
| - | } | ||
| - | |||
| - | </ | ||
| - | |||
| - | Now you see: | ||
| - | |||
| - | {{en: | ||
| - | |||
| - | ==== Your first content ==== | ||
| - | |||
| - | Let's define the content of our start page: | ||
| - | |||
| - | <code php> | ||
| - | class defaultCtrl extends jController { | ||
| - | |||
| - | | ||
| - | $rep = $this-> | ||
| - | $rep-> | ||
| - | | ||
| - | $rep-> | ||
| - | | ||
| - | return $rep; | ||
| - | } | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | So here, we put "< | ||
| - | |||
| - | {{en: | ||
| - | |||
| - | |||
| - | ==== Template of an action ==== | ||
| - | |||
| - | It should be more practical to put the content in a new template, dedicated to your action, for example in example/ | ||
| - | |||
| - | Let's create the hello.tpl in the templates directory: | ||
| - | |||
| - | <code xml> | ||
| - | <div class=" | ||
| - | < | ||
| - | |||
| - | <div class=" | ||
| - | </ | ||
| - | </ | ||
| - | |||
| - | " | ||
| - | |||
| - | <code php> | ||
| - | | ||
| - | $rep = $this-> | ||
| - | $rep-> | ||
| - | |||
| - | $tpl = new jTpl(); | ||
| - | $tpl-> | ||
| - | $rep-> | ||
| - | | ||
| - | return $rep; | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | |||
| - | Notice the use of the $tpl object. The " | ||
| - | |||
| - | You see now: | ||
| - | |||
| - | {{en: | ||
| - | |||
| - | ===== 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:// | ||
| - | |||
| - | You will see: | ||
| - | |||
| - | {{en: | ||
| - | |||
| - | |||
| - | ===== URLs ===== | ||
| - | |||
| - | To execute a specific action, you should add in the url a " | ||
| - | |||
| - | | ||
| - | |||
| - | The action parameter has the following syntax: controller_name: | ||
| - | |||
| - | However, in our example, this parameters are optional because the action has been defined as the default one in the web site. The default action is specified in the // | ||
| - | |||
| - | <code ini> | ||
| - | startModule=" | ||
| - | startAction=" | ||
| - | </ | ||
| - | |||
| - | You can change it later if you want. | ||
| - | |||
| - | Well, this urls are not very friendly, and of course, you can change how URLS should look like. For example: http:// | ||
| - | |||
| - | You can also change the " | ||
| - | |||
| - | ===== Conclusion ===== | ||
| - | |||
| - | |||
| - | This were the first concepts of Jelix. You can continue to discover it by following the [[en: | ||
| ----- | ----- | ||
| * Go back to the [[en: | * Go back to the [[en: | ||
| - | * Continue to discover Jelix with the [[en: | + | |

