Editor : How can I use foreach to populate field parameters?
Editor : How can I use foreach to populate field parameters?
pdring
Posts: 8Questions: 2Answers: 0
Hi,
Rather than hard-coding the database fields in the Editor PHP, I would like to use a foreach loop (or another technique) to populate the list based on field assignments.
Original code :
Field::inst( 'company.code' ),
Field::inst( 'company.name' ),
Field::inst( 'company.postcode' )
etc.
Ideal situation (not including the management of commas)
foreach($assignments as $assignment)
{
Field::inst( 'company.'.$assignment->field_name )
}
Thanks.
This discussion has been closed.
Answers
Hi,
Absolutely yes you can do that. Most of the examples using the chaining aspect of the API because it is convenient, however, you need to keep in mind that something like:
can just as readily be written as:
So you could put your for loop in to that code no problem!
Regards,
Allan
Awesome thanks :)