31,029
edits
m (→Other examples) |
|||
| Line 28: | Line 28: | ||
== Example for a third party == | == Example for a third party == | ||
Here is an example for the creation of a third party (eg customer company): | 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: | |||
<source lang="php"> | |||
include('/pathofdolibarrhtdocs/master.inc.php'); | |||
</source> | |||
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 master.inc.php and before calling any create or update method | |||
<source lang="php"> | |||
$user->fetch(0,'loginuser'); | |||
</source> | |||
Now we can make our business code. | |||
<source lang="php"> | <source lang="php"> | ||
| Line 33: | Line 45: | ||
include_once('/pathofdolibarrhtdocs/societe.class.php'); | include_once('/pathofdolibarrhtdocs/societe.class.php'); | ||
// We create an instance of object | // We create an instance of object to manipulate | ||
$mycompany = new Societe($db); | $mycompany = new Societe($db); | ||
// | // We set properties on object | ||
$mycompany->nom='Big Brother'; | $mycompany->nom='Big Brother'; | ||
$mycompany->client=1; | $mycompany->client=1; | ||
| Line 53: | Line 65: | ||
// To update object | // To update object | ||
$mycompany->update($user); | $mycompany->update($user); | ||
</source> | </source> | ||