DoliMobile - Back (PHP)
The dolimobile back office must be integrated into a normal dolibarr module.
So when you deploy dolimobile in your dolibarr module you will have a few new folders that will appear:
mobile
This folder will contain all the source code for the mobile part (front-end in React, see below).pwa
the folder into which the contents of the “compiled” mobile application will be copied, as well as the entry pointapi.php
smartmaker-api
the folder in which you will store the php controllers and mappers for your objects, which will be accessible via the api.php router in thepwa
As well as a file smartmaker-api-prepend.php
which is used to factorise code and avoid having php headers that are too verbose.
Mapping dolibarr <-> react application
Dolibarr objects can't be directly transposed into react, so we've developed a mapping system that matches dolibarr objects with their react equivalent.
Each dolibarr class that needs to be mapped can be mapped using a set of fine-tuned techniques, details of which can be found below.
For example, for the dolibarr Company object you will find a dmCompany class in the smartAuth project.
If your module provides a SmartInter object, for example, you can map its fields to react simply by implementing a dmSmartInter file.
More details on the mapping_dolibarr_-_react
api.php file
This is where you implement the various entry points to the API dedicated to your application.
The PHP router
This php router includes the following grammar:
- Route::action
- action can be get post or put (delete is not yet implemented)
- the 1st argument of the function is the name of the entry point you want on your api, for example
Route::get('login'…
corresponds to the http requestGET /login
- the next argument gives the name of the PHP class to be requested
- the next argument contains the name of the function to be used in this PHP class
- the last argument indicates whether it is a route for which authentication is required or not
This PHP router makes it extremely easy to 'track' the various actions possible on your API!
For example, a GET /login
calls the index
function of the AuthController class
class and a POST /login
calls the login
function of this same class …
Route::get('login', AuthController::class, 'index'); Route::post('login', AuthController::class, 'login');
Want to implement a logout? It's easy: add a line to api.php
Route::post('logout', AuthController::class, 'logout', true);
And implement the logout
function in your AuthController
…
/** * @api {post} /logout Logout * @apiDescription Logout and close session * @apiName PostLogout * @apiGroup Auth * */ public function logout($payload) {
Note: this function is of course already implemented natively in DoliMobile