Module CustomFields Dev: Difference between revisions

Jump to navigation Jump to search
→‎Storing extra options: Changed from object to associative array
(→‎Storing extra options: Changed from object to associative array)
Line 125: Line 125:
Eg:
Eg:
<source lang="php">
<source lang="php">
$extra = new stdClass(); // instanciating an empty object
$extra = array(); // $extra should always be an associative array, it's no longer an object
$extra->myproperty = 'Anything I want here'; // set a property/extra option like this
$extra['myproperty'] = 'Anything I want here'; // set a property/extra option like this
$extra->category->subcategory->prop = true; // we can set recursive properties, there's not any limit to own deep the hierarchy can be
$extra['category']['subcategory']['prop'] = true; // we can set recursive properties, there's not any limit to how deep the hierarchy can be


require_once(DOL_DOCUMENT_ROOT.'/customfields/class/customfields.class.php');
require_once(DOL_DOCUMENT_ROOT.'/customfields/class/customfields.class.php');
Line 135: Line 135:
</source>
</source>


You can also use addCustomField() or updateCustomField() with an $extra object, and these functions will also call the setExtra() method.
You can also use addCustomField() or updateCustomField() with an $extra array, and these functions will also call the setExtra() method.


'''Note''': the extra options you set are '''appended''' to the one already stored in the database. However, you can overwrite them, just use the same name of property but with a different value.
'''Note''': the extra options you set are '''appended''' to the ones already stored in the database. However, you can also overwrite previous options, just use the same name of property but with a different value (the replacement is recursive, you can do it at any level in the hierarchy).


=== Fetching extra options ===
=== Fetching extra options ===
439

edits

Navigation menu