Trace: • jelixnews-1.7 • 1.4 • 1.3.x • 1.2.x • faq
Differences ¶
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:tutorials:main:creating-application [2007/09/16 06:41] – created laurent | en:tutorials:main:creating-application [2012/04/15 08:30] (current) – laurent | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Creating | + | We're going to create |
+ | We suppose that you installed the Developer Edition of Jelix as indicated on the [[http:// | ||
- | ===== A little bit of theory ===== | ||
- | An action is a fundamental element of the framework. Every display, every form processing, every web service call is an action. | + | ===== Discovering Jelix-Scripts ===== |
- | An action | + | Jelix is provided with a script, jelix.php, which makes creation and modification of the different files of an application based on Jelix easy. It is necessary to invoke it with the command line version of PHP and to give as parameter a Jelix command name, with possible parameters and options. |
- | There are several types of requests, notably the type which is named “classic” in Jelix , for which an action can provide a response in an unspecified format: HTML, XML etc. It is for this type of request that you will generally define actions. In general, this type of request provides its parameters in the URL or the body of HTTP request (POST method). | + | <code bash> |
- | + | php jelix.php [--application_name] command_name [options] [parameters] | |
- | You also have the xmlrpc type requests (used in web services). In XML-RPC, the input data are not URL parameters, but are stored in a XML content. As XML-RPC protocol wants it, an action defined for this type of request must obligatorily provide a response to XML-RPC format. | + | </code> |
- | + | ||
- | Knowing the type of request processed and the action, Jelix knows the type of the answer to be generated, and thus controls more or less the response generation. Thus, even the error case (an exception or other) occurring during the processing of the action, the exit format will always be the awaited one. A client who calls a web service with xmlrpc, will thus have no matter what happens, a response in the xmlrpc format. That brings a certain robustness to the application. | + | |
- | + | ||
- | + | ||
- | ===== Implementing an action ===== | + | |
- | + | ||
- | The actions are implemented in so-called controllers. Controllers are classes containing methods for each action. Controllers are placed in files : | + | |
- | controllers/// | + | |
- | + | ||
- | In general, there is an index() method for the default action. | + | |
- | + | ||
- | Let's modifiy this default action. For this, open the contollers/ | + | |
- | + | ||
- | <code php> | + | |
- | class defaultCtrl extends jController { | + | |
- | | + | For this, open a console and go to the lib/jelix-scripts/ directory where jelix.php is placed. |
- | $rep = $this-> | + | |
- | return $rep; | + | <code bash> |
- | } | + | cd lib/ |
- | } | + | cd lib\jelix-scripts\ |
</ | </ | ||
- | You see there are some naming conventions. Controller classes have a name, here " | + | To get help on all the available commands, type : |
- | + | < | |
- | + | php jelix.php help | |
- | + | ||
- | + | ||
- | ==== Response object ==== | + | |
- | + | ||
- | There is an index() method, we retrieve an " | + | |
- | + | ||
- | The jResponseHtml object handles the generation of a HTML response (ie an HTML page). It generates automatically the < | + | |
- | + | ||
- | < | + | |
- | $rep-> | + | |
</ | </ | ||
- | And the browser | + | You will have noticed that you must indicate to jelix.php (except for the help command), the name of the application on which the command apply. It is possible to avoid it. For this, you have to put the name of the application in an environment variable : JELIX_APP_NAME. For our example, do this : |
- | < | + | < |
- | < | + | |
- | < | + | set JELIX_APP_NAME=news.org # under windows |
- | </ | + | |
</ | </ | ||
- | All the body of the page, i.e the content of the html tag < | ||
- | Before beginning to code, let's see the content of the template | ||
+ | Notice that you can execute the script from any directories. For example, you can type: | ||
- | ==== The template ==== | + | < |
- | + | | |
- | Create a newslist.tpl file in the templates directory of the module. And place this content inside : | + | |
- | + | ||
- | < | + | |
- | | + | |
- | | + | |
</ | </ | ||
- | As we said earlier, the content of the template will be the content of the < | ||
+ | ===== Creation of an application ===== | ||
+ | Let's begin to create our application. Jelix proposes a command for creating all the tree structure of an application : createapp. Type then : | ||
- | ==== Using the template in the action ==== | + | < |
- | + | php jelix.php createapp | |
- | Let's see what we now have in the controller : | + | |
- | + | ||
- | < | + | |
- | class defaultCtrl extends jController { | + | |
- | + | ||
- | | + | |
- | $rep = $this-> | + | |
- | $rep-> | + | |
- | $rep-> | + | |
- | return $rep; | + | |
- | } | + | |
- | } | + | |
</ | </ | ||
- | We the added an instruction to specify to the response that we use the newslist.tpl template. | + | You then get a news.org/ directory, at the same level as the lib/ directory. Its content |
- | A selector comprise a module name and a resource name separated | + | news.org/ |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | Check that the temp/ | ||
+ | ===== Creation of a module ===== | ||
- | ===== First | + | Now we have a skeleton of application, |
- | We are now ready to display the first version of our action. For this, type the following url in your browser : | + | The actions |
- | http:// | + | < |
- | + | php jelix.php createmodule | |
- | You will then see the content of the template we created on the screen. | + | |
- | + | ||
- | The action parameter is the name of the action to be executed. It is made from to parts, separated by an underscore (_). The first part is the name of the controller, the second part is the name of the method to be executed. | + | |
- | + | ||
- | We can specify that this action will be the default action of the application. For this, open the configuration file actu.org/ | + | |
- | + | ||
- | < | + | |
- | defaultModule = "news" | + | |
- | defaultAction = " | + | |
</ | </ | ||
- | You can then use the following url : | + | By typing this command, Jelix has created for you a module named news with all its tree structure and some mandatory files : |
- | + | ||
- | http:// | + | |
- | To display our first page. | + | news.org/ |
+ | news/ the directory of the module | ||
+ | module.xml | ||
+ | controllers/ | ||
+ | | ||
+ | classes/ | ||
+ | daos/ the object-relationnal mapping files | ||
+ | locales/ | ||
+ | en_EN/ | ||
+ | fr_FR/ | ||
+ | templates/ | ||
+ | zones/ | ||
+ | We are now ready to define the actions. | ||
- | ---- | ||
- | * Next : [[en: | ||
- | * Previous : [[en: | ||
- | * [[en: |