Create the first controller with Alxarafe for Alixar (Fork of Dolibarr)

For this point of the program, you need to have installed Alxarafe 0.0.7 or higher. We continue advancing in Alxarafe as we advance in Alixar.

The Dispatcher.

Dispatcher is a class that performs two basic functions:

  • Defines application constants.
  • Determines which controller is going to be used depending on the variables that are passed by POST.

By default, Alxarafe uses the call variable for the class name (which must exist in the Controller folder), and run for the name of the method to execute.

For example:

We do not want to interfere with this form of work, because we will start using it now, but we want to keep the option of making an include of the Dolibarr file as until now, so that if we use call will load the class, and if we use controller, the include.

To do this, in the Helpers folder, we have created a class called AlixarDispatcher that extends the original dispatcher from Alxarafe.

If you analyze the AlixarDispatcher code, you will see that it is very simple. It only has two methods:

  • defineConstants(), which simply invokes the parent to define the Alxarafe constants, and then defines its own.
  • process(), which first releases the Alxarafe dispatcher process, and if it succeeds returns true; If that does not succeed, try locating the file to use for the include, putting the name in the variable $this->path, since it should be included from the index.php and not, into the class.

The Controller.

The controller is nothing more than a class extending from AlxarafeBaseControllers.

We will try this code:

class AdvancedAccountancy extends \Alxarafe\Base\Controller
public function run()
echo 'main in AdvancedAccountancy';
public function try2()
echo 'try2 in AdvancedAccountancy';

Only by creating this driver within the Controllers folder, we will already have the following addresses available:

Note that in the first case, it is indistinct to put &run=run, because by default, if nothing is indicated, we assume that the run method is executed.

Soon we will see how to use the views with Twig and begin to simplify the structure of Dolibarr to improve the score of Scrutinizer.

Remember that you can follow the evolution of the Code, and collaborate on the advances, in:

Leave a comment

Your email address will not be published. Required fields are marked *