Chapter: Define commons processes between many actions

−
Table of content

There are two type of treatments: business processes, and those to generate the
web content. For business processes, you create some classes, which use jDao,
working with a database. These classes can be used by all modules, so this is a
way to execute some common processes. See the section about the use of business classes.

For the generation of web content, this is a little more complex because there are several ways of doing things. In most of cases, we have several pages that have some parts in common. This may be a banner, a footer, a menu on the side etc. .. There may be some pages which have more than these common "zone". Here are some various solutions, depending on the context, to create some common processes

If several actions of several controllers have some treatments in commons (but not all), then you can use the mechanism of object inheritance. This means you create a "base" controller, which will not be used directly, but other controllers will inherits from it.

Here is an example of a base controller, in the file controllers/myBaseController.php:

Of course, the controller may contain basic properties, other methods, and also some methods which can be overrided.

The inheritance can be used to create for example a CRUD controller which implements many methods to create an interface to manage some datas (CRUD), and then, you have just to inherit from this controller to create quickly a CRUD interface. In fact, Jelix have a such controller to create CRUD interface.

A web page is built with several parts, and each part can be reused through many pages (not necessarily all). Those common blocks should be defined once (and cached optionnally) and be easily usable throughout your application.

Of course, if you have common content included on every pages, previous tips or objects are not very purposeful.
You have to create a customized response by inheriting a default one. See chapter on the creation of customized responses.

This manual is distributed under the terms of licence Creative Commons by-nc-sa 3.0. Therefore you're allowed to copy, modify and distribute and transmit it publicly under the following conditions: Attribution, Noncommercial, Share Alike.