We saw how to create a simple form. However, we didn't have a full interface to administrate the data: verification of the content, display of errors, list of the news and links to modify, delete... Jelix facilitate the development of such features : a powerfull form system and a controller to do CRUD (Create/Read/Update/Delete). ===== Creating a form with jForms ===== The first thing to do is to create a form using jForms. It is an XML file in which you declare all controls of the form, and their labels, their constraints etc. It exists a command in jelix-scripts to create quickly a jForms form from a dao file. We will use of course the dao we created in the previous chapter. Go to the jelix-scripts directory and execute this command: php jelix.php createform news newsform news The createform command takes three arguments : - the name of the module, - the name of the futur form, - the name of the dao. Then you have a new file **news.org/modules/news/forms/newsform.form.xml** :
The generated form is very basic and most of time you have to modify it because the script cannot guess what you want exactly. For example, here, you have to modify the labels to have better labels. Perhaps you want other controls.. And here, we want also to add some constraints and help.
The format is aaaa-mm-jj
Now the form is ready. We could use the jForms API to manipulate the form, but the controller we're going to use do it for us. ===== Creating a CRUD controller ===== Create the file modules/news/controllers/admin.classic.php, and start to write the controller: Here the controller doesn't inherits from jController, but from jControllerDaoCrud. This is a controller which contains predefined actions to list, create, modify, save and delete records. So you just have to fill some properties to have a full management of the news. A minimal setup is to indicate the dao and the form to use in the controller: Now try to display the main action of the controller: http://localhost/jelix/news.org/www/index.php?module=news&action=admin:index You should obtain... an empty page ! In fact, the controller use the default html response and set nothing on it since most of time you will define a personnalized html response, as it is indicated [[http://docs.jelix.org/en/manual-1.0/common-processes#customizing-common-response|in this page]]. Since we didn't develop a such response in the tutorial, we're going to redefine a method of the controller to prepare the response. This method is _getResponse, specific to jControllerDaoCrud. getResponse('html'); $rep->title = "News management"; $rep->bodyTpl = "admin_news"; return $rep; } } ?> Let's create the template modules/news/templates/admin_news.tpl:

News management

{$MAIN}
Retour to homepage
Now, if you relaunch http://localhost/jelix/news.org/www/index.php?module=news&action=admin:index, you should see a list of news, with links to modify, delete etc. You can override the template to change them and adding informations or what you want. === Note === If you want to create a CRUD on a new table (so no DAO and forms on this table), you can create it in a single command: php jelix.php createdaocrud the_module the_table_name It creates the controller, the dao and the form file. Then you can see directly the manager: site.com/index.php?module=the_module&action=default:the_table_name