Quick links: Content - sections - sub sections
EN

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
en:tutorials:minitutorial:1.0.3 [2008/04/03 22:50] – created laurenten: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:tutorials:minitutorial:1.0.2|follow this tutorial instead]]. 
- 
- 
-===== Download and installation ===== 
- 
-First, [[en:download:stable|download the "developer" edition of Jelix]]. Jelix needs at least PHP 5.2. 
- 
-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/lib/ in which there are all libraries used by jelix, and jelix itself. 
- 
-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://localhost/jelix-1.0.3/. (You can rename //jelix-1.0.3// as you wish). 
- 
-===== Jelix scripts ===== 
- 
-A script for command line, jelix.php, is available in the lib/jelix-scripts/ directory. This script allows you to create quickly some differents files for your application. So open a console and go into this directory : 
- 
-<code bash> 
-   cd lib/jelix-scripts/        # under linux 
-   cd lib\jelix-scripts\        # under windows  
-</code> 
- 
-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] 
-</code> 
- 
- 
-===== Creation of an application ===== 
- 
-Let's create the tree structure of the application using the createapp command. Our application will be named "example": 
- 
-<code bash> 
-php jelix.php --example createapp 
-</code> 
- 
-You will then get a example/ directory, at the same level as the lib/ directory. Its content is the following : 
- 
-  example/ 
-     modules/       the modules of your application 
-     plugins/       the plugins of your application 
-     var/config/    the configuration files of your application 
-     var/log/       the log files 
-     var/themes/    the different possible themes in your application 
-     var/overloads/  will contain the different files that you will redefine, from other modules.  
-     www/           the root of the site 
- 
- 
- 
-===== 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 //createapp// command. 
- 
-Here is the directory which has been created: 
- 
-   example/modules/ 
-              example/                the directory of the module 
-                module.xml          file describing the identity of the module 
-                controllers/       the classes processing the actions 
-                   default.classic.php   a default controller 
-                classes/            your business classes and services 
-                daos/               the object-relational mapping files 
-                forms/              forms files 
-                locales/            locales files ("properties files") 
-                    en_EN/ 
-                    fr_FR/ 
-                templates/          templates of the module 
-                zones/              objects processing specific zones in a page 
- 
- 
-If you want to create other modules later, you can use the //createmodule// command: 
-<code bash> 
-php jelix.php --example createmodule cms 
-</code> 
- 
-It will create a module named "cms". 
- 
- 
-===== First display ===== 
- 
-Before to display the start page of your new application, you should put write access on some directories for the web server. This directories are temp/example and example/var/log :  
- 
-For example, on linux (ubuntu or debian) : 
- 
-<code bash> 
-   chown www-data:www-data ../../temp/exemple ../../exemple/var/log 
-   chmod 755 ../../temp/exemple ../../exemple/var/log 
-</code> 
- 
-We are now ready to display the page. Your application is accessible at this URL: http://localhost/jelix-1.0.3/example/www/. Enter this URL in your browser. you should see: 
- 
- 
-You notice this message saying that a CSS file is missing. Copy the jelix-1.0.3/lib/jelix-www  directory in dans jelix-1.0.3/example/www  by renaming it to "jelix" (on a dedicated apache server, it is better to create an alias). This directory is important because it contains some files needed by jForms or other components. 
- 
-Now you should see: 
- 
- 
-It there are some error messages in "installation check", fix them. 
- 
- 
- 
-STOP HERE. tutorials not still updated for Jelix 1.0.3 
- 
- 
- 
- 
- 
-===== Action implementation ===== 
- 
-Let's implement a default action. Open the controllers/default.classic.php file and modify the content this way : 
- 
-<code php> 
-class defaultCtrl extends jController { 
- 
-   function index () { 
-      $rep = $this->getResponse('html'); 
- 
-      return $rep; 
-   } 
-} 
-</code> 
- 
-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 <head> part of HTML, from some of its properties. Let's define the title of the page : 
- 
-<code php> 
-   $rep->title = 'Hello World !'; 
-</code> 
- 
-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->bodyTpl = 'hello'; 
-</code> 
- 
-We don't put the ".tpl" part because the content of the string is actually a Jelix //selector//. A Jelix selector is a shortcut to refer to a resource of a module. 
- 
-Note that you can create your own response objects (possibly deriving from the class jResponseHtml), and so to put at it all common process to several or all your actions, so this process will not have to be duplicate in each action (like the name of the template, the inclusion of common zones etc.). 
- 
-==== The template ==== 
- 
-Create a hello.tpl file in the template directory of the module. And put in this content : 
- 
-<code xml> 
-  <h2>Hello {$name} !</h2> 
-  <p>Welcome in Jelix !</p> 
-</code> 
- 
-"{$name}" is a template variable : it will be replaced by the value you will define, like in this example :  
- 
-<code php> 
-      $rep->body->assign('name','Me'); 
-</code> 
- 
- 
- 
-==== As a summary ==== 
- 
-The code of the controller must now be like this : 
- 
-<code php> 
-class defaultCtrl extends jController { 
- 
-   function index () { 
-      $rep = $this->getResponse('html'); 
-      $rep->title = 'Hello World !'; 
-       
-      $rep->bodyTpl = 'hello'; 
-      $rep->body->assign('name','Me'); 
-     
-      return $rep; 
-   } 
-} 
-</code> 
- 
- 
- 
-===== First display ===== 
- 
-We are now ready to display our page. For this, give the following URL : 
-  http://localhost/jelix/helloapp/www/index.php?module=hello&action=default:index 
- 
-You will then see your html page, with the welcome message. 
- 
-The url can change regarding the configuration of your installation, especially if you have specified the document root of the site on the directory helloapp/www. You have to know that Jelix can handle significant url to avoid all this disgusting parameters.  
- 
-===== 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->param('name'); 
-   $rep->body->assign('name', $name); 
-</code> 
- 
-Now type : 
-    http://localhost/jelix/helloapp/www/index.php?module=hello&action=default:index&name=Robert 
- 
- 
-===== Conclusion ===== 
- 
-This were the first concepts of Jelix. You can continue to discover him by following the [[en:tutorials:main|main tutorial]]. 
- 
------ 
-   * Go back to the [[en:documentation|documentation]] 
-   * Continue to discover Jelix with the [[en:tutorials:main|main tutorial]] 
  

en/tutorials/minitutorial/1.0.3.txt · Last modified: 2008/11/19 15:02 by 127.0.0.1

Recent changes RSS feed Creative Commons License