Business Objects

From Dolibarr Open Source ERP CRM Wiki

Return to developer
documentation index

File Doc dev.png


Business objects

All business objects are defined by a PHP class that inherits the class CommonObject (defined in file commonobject.class.php). Every business object has the 4 CRUD methods you can use to read or save into database:

  • Create: create()
  • Read: fetch()
  • Update: update()
  • Delete: delete()

See examples later...

Link between Business objects

Some business objects are linked to other business objects. This is done in Dolibarr using the Table llx_element_element. But you don't have to read this table to get objects linked to another. This is a portion of code that shows how you can do this:

// This load the array linked_object with objects that link to this one
$object->load_object_linked($object->id, $object->element);
// To load array linked_object with objects that are linked by this one
$object->load_object_linked($object->id, $object->element);
// Then choose id with objects type you need
$org_order_array = $object->linked_object["commande"];
// Now use them
$thelinkedobjectid = $org_order_array[0];
// new order instance
$thelinkedobject = new Commande($object->db);
// load the object


Example for a third party

Here is an example for the creation of a third party (eg customer company):

If we make a new script or an external script, we must add at the beginning, before making anything else:


This will initialize Dolibarr environment objects ($conf, $db, $lang and $user). If we want that actions (create, update) are tagged with a particular user as the create/update user, we must do after the include of and before calling any create or update method


Now we can make our business code.

// We declare the class we want to use
// We create an instance of object to manipulate
$mycompany = new Societe($db);
// We set properties on object
$mycompany->nom='Big Brother';
// If we want that creation is tagged as done by a particular user 'loginuser',
// you must uncomment this line to load all characteristics of this user.
// If we keep the comment, Dolibarr will use null into fields that should store the create or update user.
// $user->fetch('loginuser');
// We call method to create
// This is to read/load an already created object
// To update object
$mycompany->nom='Big Brother 2';

Other examples

You may find other example for manipulating Dolibarr objects (Create, Read, Update, Delete) into directory dev/samples of Dolibarr snapshot.

Personal tools
  • Ask to to request an account to contribute to this documentation
  • Log in
In other languages
No translation in Deutsch.
No translation in Italian.
No translation in Greek.

Social networks
Follow us on Google+ Follow us on Facebook Follow us on LinkedIn Follow us on Twitter