439
edits
| Line 406: | Line 406: | ||
=== Printing in documents === | === Printing in documents === | ||
printField() | '''printField()''' is used to properly print and translate a custom field's record's value. Generally, you can just print the custom field's value as-is, but in a few cases (eg for boolean types, or constrained fields), using the printField() method will more properly print the value. | ||
<source lang="php"> | |||
print $customfields->printField($field, $value, $outputlangs=''); | |||
</source> | |||
Where: | |||
* $field is the custom field's SQL structure as an object (eg: returned by fetchFieldStruct()). | |||
* $value is the custom field's value for the current record (eg: $customfields->fields->myfield). | |||
* $outputlangs is the Translate object for the target language. | |||
For example, with a constrained field with Smart Value Substitution, instead of printing the id like 1, it will print the full name of user like FirstName Name. | |||
This method will also translate a value if a translation is found in the language files. | |||
Another method '''printFieldPDF()''' can be used to properly print a value for a PDF (properly encoding the characters). | |||
=== Simple printing in documents === | === Simple printing in documents === | ||
simpleprintField() simpleprintFieldPDF() | If you don't want to have to manually fetch the structure of every custom field whose you want to print the value, you can then use a simplifier method called '''simpleprintField()''' which will take as input a custom field name instead of a custom field SQL structure object. | ||
This method is just a simplifier (Facade) wrapper for the printField() method, and thus will have the same advantages (fetch constrained fields, values translation, etc.). | |||
<source lang="php"> | |||
print $customfields->simpleprintField($fieldname, $value, $outputlangs=''); | |||
</source> | |||
Where: | |||
* $fieldname is the custom field's name (eg: "myfield"). | |||
* $value is the custom field's value for the current record (eg: $customfields->fields->myfield). | |||
* $outputlangs is the Translate object for the target language. | |||
Another method '''simpleprintFieldPDF()''' can be used to properly print a value for a PDF (properly encoding the characters). | |||
=== Find the label === | === Find the label === | ||
edits