Bureaucrats, emailconfirmed, Administrators
44
edits
mNo edit summary |
No edit summary |
||
| Line 16: | Line 16: | ||
Each object have his table in database to store values of extrafields. | Each object have his table in database to store values of extrafields. | ||
==Datatables extrafield tables models | == Datatables extrafield tables models == | ||
llx_''BaseTableNAme''_extrafields | llx_''BaseTableNAme''_extrafields | ||
rowid integer AUTO_INCREMENT PRIMARY KEY, | rowid integer AUTO_INCREMENT PRIMARY KEY, | ||
| Line 23: | Line 23: | ||
import_key varchar(14) | import_key varchar(14) | ||
== | == Load class for extrafields == | ||
To use extrafields all pages need include | |||
<source lang="php"> | <source lang="php"> | ||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; | ||
</source> | </source> | ||
==Load extrafield array in object | == Load extrafield array in object == | ||
<source lang="php"> | <source lang="php"> | ||
$extrafields = new ExtraFields($db); | $extrafields = new ExtraFields($db); | ||
| Line 34: | Line 36: | ||
</source> | </source> | ||
==Load extrafield into object | $extralabels will be an array with code and label of extrafields. | ||
== Load extrafield into object == | |||
Extrafields are loaded in $object->array_options array. | |||
<source lang="php"> | <source lang="php"> | ||
$object->fetch($rowid); | |||
$object->fetch_optionals($rowid,$extralabels); | |||
</source> | </source> | ||
==Before call | == Before call $object->create() or $object->update() == | ||
Values of extrafields sent by form need to be retrieve. For do that, use this method : | |||
<source lang="php"> | <source lang="php"> | ||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); | $ret = $extrafields->setOptionalsFromPost($extralabels,$object); | ||
</source> | </source> | ||
==Inside edit page to display extrafields | |||
== Inside edit page to display extrafields == | |||
<source lang="php"> | <source lang="php"> | ||
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook | $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook | ||
if (empty($reshook) && ! empty($extrafields->attribute_label)) | if (empty($reshook) && ! empty($extrafields->attribute_label)) | ||
{ | { | ||
print | print $object->showOptionals($extrafields,'edit'); | ||
} | } | ||
</source> | </source> | ||
==Inside view page to display extrafields | == Inside view page to display extrafields == | ||
<source lang="php"> | <source lang="php"> | ||
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook | $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook | ||
if (empty($reshook) && ! empty($extrafields->attribute_label)) | if (empty($reshook) && ! empty($extrafields->attribute_label)) | ||
{ | { | ||
print | print $object->showOptionals($extrafields); | ||
} | } | ||
</source> | </source> | ||
==After fetch method of this object class | == After fetch method of this object class == | ||
<source lang="php"> | <source lang="php"> | ||
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); | require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); | ||