Trace: • creating-application
Chapter: Creating an application and a module
|« Foreword||Creating a first simple action »|
Table of Contents
We're going to create an application from scratch. Every Jelix application has a name : the name of its directory. We will call our application “news.org”.
We suppose that you have installed PHP 7 (or at least 5.6), PHP-CLI, and Composer.
Create a directory for your project, initialise a composer.json file, and install
mkdir projects cd projects composer init composer require "jelix/jelix-standard:^1.7.0"
At the end, you have a new directory
vendor, containing the source code
of Jelix and other packages.
Jelix is provided with several scripts to execute in a command line, which makes easy the creation and the modification of different files of a Jelix application.
The first one,
vendor/bin/create-jelix-app, allows to create a Jelix application.
You have to give to it the new directory of the application
Two other scripts,
console.php, are available inside the
dev.php helps the developeur to construct his application,
console.php helps the administrator to manage the application data
and other things.
Let's begin to create our application. Go into the
projects directory and type:
vendor/bin/create-jelix-app --no-default-module news.org
A number of questions are asked to you, to help you to configure the project. For this tutorial, let's keep the default answer, except for the question “How to install jelix-www files?”, for which you choose “copy”.
The web site of your company > The licence of your application and modules (default is 'All rights reserved') > The url to the licence if any > Copyright on your application and modules (default is '2019 news.org') > The suffix of your modules id (default is '@news.org') > The creator name (your name for example) (default is 'news.org') > The email of the creator > How to install jelix-www files? copy: will be copied into the www/ directory filelink: a symbolic link into the www/ directory will point to the lib/jelix-www directory vhost: you will configure your web server to set an alias to the lib/jelix-www directory (default is '')  copy  vhost  filelink > 0 Web path to the content of lib/jelix-www? (default is 'jelix/') > Do you want to store sessions into a database? ( 'y' or 'n', default is n) > Do you want to store sessions as files into a specific directory? ( 'y' or 'n', default is n) >
As a result, you'll get an
example/ directory, at the same level as the
vendor/ directory. Its content will be :
news.org/ app/ system/ the configuration files of your application responses/ custom response object for the application (views) themes/ the different possible themes in your application overloads/ will contain the different files that you will redefine, from modules. application.init.php the file to initialize the jelix environment and the application console.php the script to launch some commands to manage the application dev.php the script to launch some commands to develop modules/ the modules of your application plugins/ the plugins of your application temp/ It contains all cache and temporary file generated by jelix. var/ config/ the configuration files of your application, that are specific to the environment and the server log/ the log files www/ the root directory of the site (public files)
Note that we used the option
--no-default-module with the script
create-jelix-app. Without this option, the script create a module
having the same name of the application (so
But in this tutorial, we want to create ourselves the module, to learn
Now we have a skeleton of application, we have to create a module, because for the moment, our application can do nothing since there is no defined action. Indeed, we will have to declare and implement some actions. An action can display a page, save data of a form, response as a webservice, etc.
The actions are grouped into distinct modules according to the domain or the
function to which they are linked. We will for example create a module which
will group the actions meant to display and manage the news. To do that, you
module:create command, which takes as parameter the name of the module
that will be created. Use the
dev.php script inside
php dev.php module:create news --default-module
By typing this command, Jelix has created for you a module named
all its tree structure and some mandatory files :
news.org/modules/news/ ├── classes your business classes and services ├── controllers your controllers │ └── default.classic.php a controller ├── daos the object-relationnal mapping files ├── forms forms files ├── install │ ├── configure.php script to configure the module │ └── install.php script to install the module ├── locales locale files ("properties" files) │ ├── en_US │ └── fr_FR ├── module.xml file describing the identity of the module ├── templates templates of the module ├── urls.xml urls mapping └── zones objects processing specific zones in a page
We are now ready to define the actions.