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:

Set a single entry point

The first significant change we make in Alixar (based on a copy of Dolibarr 10 ERP) is to create a single entry point.

Alixar, unlike Dolibarr, will have only one entry point, which will be the index.php file in the main folder. In Dolibarr, the different options of the application run directly executing the corresponding file.

The way Dolibarr does it means at least 2 serious problems:

  • It can be easier to hack, having to control many entry points
  • Every time you need to access a common file, you have to keep in mind that the application runs from different folders, so when you don’t know the entry point, we need to know the path from the executable file.

The main problem is that it involves a very important change in the way the application works, and therefore it is difficult to do without breaking the code.

The code will be broken for a few days until the process is completed, and still, there will be no guarantees that everyone is fixed.

How do you get a single entry point?

To obtain a single point of entry, the original routes of Dolibarr are renamed as follows:

It would be as follows.

It could be the case that there were more levels of nesting, for example compta/bank/card. PHP would happen to be ?controller=compta/bank&method=card.

As you can see, this change involves changing all the links in all the pages and menus to the new format.

You can review the evolution of the code in the official repository: