Trace:
no way to compare when less than two revisions
Differences ¶
This shows you the differences between two versions of the page.
| — | en:tutorials:minitutorial:1.5.x [2013/02/20 11:45] (current) – created laurent | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Mini Tutorial ====== | ||
| + | |||
| + | The goal of this tutorial is to quickly show how you can develop an application with Jelix 1.5. | ||
| + | |||
| + | |||
| + | ===== Download and installation ===== | ||
| + | |||
| + | First, [[en: | ||
| + | |||
| + | Unpack the archive file you have downloaded, with your archiver software companion. For example, with tar (replace x with you'r version): | ||
| + | |||
| + | <code bash> | ||
| + | tar xzf jelix-1.5.x-dev.tar.gz | ||
| + | </ | ||
| + | |||
| + | After this, you have a directory @@F@jelix-1.5.x-dev/ | ||
| + | |||
| + | For the purpose of this tutorial, rename the jelix-1.5.x-dev folder to jelix and move it in a directory of your web site. So that it will be accessible with a browser, at this URL for example: @@http:// | ||
| + | |||
| + | ===== Jelix scripts ===== | ||
| + | |||
| + | A script for command line, @@F@createapp.php@@, | ||
| + | |||
| + | <code bash> | ||
| + | cd jelix/ | ||
| + | </ | ||
| + | |||
| + | To invoke the command, run the script @@createapp.php@@ with the php binary (php.exe under windows), and give it the path of the new application | ||
| + | <code bash> | ||
| + | php createapp.php path/ | ||
| + | </ | ||
| + | |||
| + | After creating the application, | ||
| + | |||
| + | ===== Application creation ===== | ||
| + | |||
| + | Let's create the tree structure of your application using @@createapp@@ command. Suppose your application will be named " | ||
| + | |||
| + | <code bash> | ||
| + | php createapp.php ../ | ||
| + | </ | ||
| + | |||
| + | As a result, you'll get an @@F@example/ | ||
| + | |||
| + | < | ||
| + | example/ | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | An other directory @@F@temp/ | ||
| + | |||
| + | ===== Module creation ===== | ||
| + | |||
| + | A module gathers a whole set of actions dispatched in controllers. At least one is necessary in an application. This is why a module is created automatically when you run @@createapp@@ command. | ||
| + | |||
| + | 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, use @@createmodule@@ command with the @@F@cmd.php@@ script: | ||
| + | |||
| + | <code bash> | ||
| + | php cmd.php createmodule cms | ||
| + | </ | ||
| + | |||
| + | It will create a module named " | ||
| + | |||
| + | |||
| + | ===== First display ===== | ||
| + | |||
| + | Before displaying the start page of your new application, | ||
| + | |||
| + | For example, on linux (ubuntu or debian) : | ||
| + | |||
| + | <code bash> | ||
| + | sudo chown www-data: | ||
| + | sudo chmod 755 ../ | ||
| + | </ | ||
| + | |||
| + | You are now ready for prime. Your application is accessible at this URL: @@http:// | ||
| + | |||
| + | {{en: | ||
| + | |||
| + | Noticed this message saying that a CSS file is missing ? Copy the @@F@jelix/ | ||
| + | |||
| + | Now you should see: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | If there are some error messages in the " | ||
| + | |||
| + | |||
| + | ===== 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 " | ||
| + | |||
| + | Open @@F@example/ | ||
| + | |||
| + | <code php> | ||
| + | /** | ||
| + | * @package | ||
| + | * @subpackage example | ||
| + | * @author | ||
| + | * @copyright 2013 yourname | ||
| + | * @link http:// | ||
| + | * @license | ||
| + | */ | ||
| + | |||
| + | class defaultCtrl extends jController { | ||
| + | /** | ||
| + | * | ||
| + | */ | ||
| + | | ||
| + | $rep = $this-> | ||
| + | |||
| + | // this is a call for the ' | ||
| + | // remove this line ! | ||
| + | | ||
| + | |||
| + | | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | What this code means is that **index** action of **default** controller retrieves a @@C@jResponseHtml@@ object through the @@M@getResponse()@@ method by passing " | ||
| + | |||
| + | |||
| + | @@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 ' | ||
| + | |||
| + | <code php> | ||
| + | |||
| + | class defaultCtrl extends jController { | ||
| + | /** | ||
| + | * | ||
| + | */ | ||
| + | | ||
| + | $rep = $this-> | ||
| + | |||
| + | | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Response object ==== | ||
| + | |||
| + | a @@C@jResponseHtml@@ object generates an HTML response (an HTML page). It automatically generates the @@< | ||
| + | |||
| + | Let's define the title of the page. Add this in the @@M@index()@@ method, just before returning the response object: | ||
| + | |||
| + | <code php> | ||
| + | | ||
| + | </ | ||
| + | |||
| + | Reload the page. The page title should now display accordingly in your browser title bar. But still your page contains this: | ||
| + | |||
| + | {{en: | ||
| + | |||
| + | How is this possible whereas we don't define any content in our controller? | ||
| + | |||
| + | We have seen before that @@M@getResponse(' | ||
| + | |||
| + | Let's see the content of @@F@example/ | ||
| + | |||
| + | <code php> | ||
| + | require_once (JELIX_LIB_CORE_PATH.' | ||
| + | |||
| + | class myHtmlResponse extends jResponseHtml { | ||
| + | |||
| + | public $bodyTpl = ' | ||
| + | |||
| + | function __construct() { | ||
| + | parent:: | ||
| + | |||
| + | // Include your common CSS and JS files here | ||
| + | } | ||
| + | |||
| + | protected function doAfterActions() { | ||
| + | // Include all process in common for all actions, like the settings of the | ||
| + | // main template, the settings of the response etc.. | ||
| + | |||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | This " | ||
| + | |||
| + | <code html> | ||
| + | < | ||
| + | | ||
| + | </ | ||
| + | |||
| + | @@{$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 " | ||
| + | |||
| + | @@M@doAfterActions@@ method is called after each action. In the example, it assigns @@"< | ||
| + | |||
| + | Now you know why there is a content displaying 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 @@M@doAfterActions@@ method, we add an instruction to setup a CSS style sheet: | ||
| + | |||
| + | <code php> | ||
| + | require_once (JELIX_LIB_CORE_PATH.' | ||
| + | |||
| + | class myHtmlResponse extends jResponseHtml { | ||
| + | |||
| + | public $bodyTpl = ' | ||
| + | |||
| + | function __construct() { | ||
| + | parent:: | ||
| + | $this-> | ||
| + | // Include your common CSS and JS files here | ||
| + | } | ||
| + | |||
| + | protected function doAfterActions() { | ||
| + | // Include all process in common for all actions, like the settings of the | ||
| + | // main template, the settings of the response etc.. | ||
| + | |||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Now you see: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ==== Your first content ==== | ||
| + | |||
| + | Let's define the content of our start page (in @@F@example/ | ||
| + | |||
| + | <code php> | ||
| + | class defaultCtrl extends jController { | ||
| + | |||
| + | | ||
| + | $rep = $this-> | ||
| + | $rep-> | ||
| + | | ||
| + | $rep-> | ||
| + | | ||
| + | return $rep; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | So here, we put "< | ||
| + | |||
| + | {{: | ||
| + | |||
| + | |||
| + | ==== Template of an action ==== | ||
| + | |||
| + | It should be more practical to put the content in a new template, dedicated to your action, for example in @@F@example/ | ||
| + | |||
| + | Let's create the @@F@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: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ===== 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 @@M@param()@@ method: | ||
| + | |||
| + | <code php> | ||
| + | $name = $this-> | ||
| + | | ||
| + | </ | ||
| + | |||
| + | Now type: | ||
| + | http:// | ||
| + | |||
| + | You will see: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | |||
| + | ===== URLs ===== | ||
| + | |||
| + | To execute a specific action, you should add in the url the module name, the controller name, and the method name of the action. For our example, we can type: | ||
| + | |||
| + | | ||
| + | |||
| + | (If it doesn' | ||
| + | |||
| + | In our example, the url indicates the default action of the application. which is specified in the @@F@example/ | ||
| + | |||
| + | <code ini> | ||
| + | startModule=" | ||
| + | startAction=" | ||
| + | </ | ||
| + | |||
| + | You can change it later if you want. | ||
| + | |||
| + | You can also define your own URL by using an other URL engine provided by Jelix. And finally, you can 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: | ||
| + | * Continue to discover Jelix with the [[en: | ||

