API, module custom et objets

Salut,

J’ai un module créé via le module builder et celui-ci comporte plusieurs objets. Lorsque je vais sur l’onglet d’un objet et que je génère un fichier API celui-ci prend le nom du module et le remplit avec les informations de l’objet.
J’ai renommé ces fichiers en api_monobjet.class.php pour chaque objet du module et je les ai placés dans un dossier « class/api » pour mieux ranger les choses.

Comment je pourrais avoir une api de ce style :

{{DOMAIN}}/dolibarr/htdocs/api/index.php/monmodule/objet1
{{DOMAIN}}/dolibarr/htdocs/api/index.php/monmodule/objet2
{{DOMAIN}}/dolibarr/htdocs/api/index.php/monmodule/objet3

etc.

Merci !

Trouvé :

class MonApi extends DolibarrApi
{
	/**
	 * @var Object1Api $object1 {@type Object1Api}
	 */
	public $object1;

        /**
	 * @var Object2Api $object2 {@type Object2Api}
	 */
	public $object2;

	/**
	 * Constructor
	 *
	 * @url     GET /
	 *
	 */
	public function __construct()
	{
		global $db, $conf;
		$this->db = $db;

		dol_include_once('/monmodule/class/api/api_object1.class.php');
		dol_include_once('/monmodule/class/api/api_object2.class.php');

		$this->object1 = new Object1Api($this->db);
		$this->object2 = new Object2Api($this->db);
	}

	/**
	 * Get properties of a object1 object
	 *
	 * Return an array with object1 informations
	 *
	 * @param 	int 	$id ID of object1
	 * @return 	array|mixed data without useless information
	 *
	 * @url	GET object1/{id}
	 *
	 * @throws RestException 401 Not allowed
	 * @throws RestException 404 Not found
	 */
	public function getObject1($id){
		return $this->object1->get($id);
	}

       /**
	 * Get properties of a object2 object
	 *
	 * Return an array with object2 informations
	 *
	 * @param 	int 	$id ID of object2
	 * @return 	array|mixed data without useless information
	 *
	 * @url	GET object2/{id}
	 *
	 * @throws RestException 401 Not allowed
	 * @throws RestException 404 Not found
	 */
	public function getObject2($id){
		return $this->object2->get($id);
	}
1 « J'aime »