Hi,
I would like to be able to add to my backend item form some readonly fields. I have read some posts in the forum, this in particular:
http://www.j-cook.pro/forum/9-coding-inside-your-component/1761-editing-multiple-tables-in-one-view#1882]
but I'm still a bit lost.
Let's take the tutorial "travel" component as an example, supposing that:
1) One can not use the Cook filters (they are still disabled).
2) The "Voyages" table has one additional field "Scope" filled by a textarea inside the "Voyages" backend item page (values could be "Job", "Holiday" or any other string value).
The user inserts these information using the "Voyages" item form:
Andrew - Lyon - Job
Andrew - Marseille - Holiday
Andrew - Bordeaux - Job
Then, he/she opens the "Voyageur" collection, selects "Andrew" to edit the data and, inside the item form, after the combo "Utilisateur -> Username", a field with label "Voyages" shows these readonly info:
Lyon, Job
Marseille, Holiday
Bordeax, Job
If no Voyages exist for Andrew, the field "Voyages" should appear empty.
GENERAL IDEAS
A - I thought a first step could be adding a textarea field inside admin/models/forms/voyageur.xml.
B - Then I need to add a function to the model (admin/models/voyageur.php) that executes the query (it could be a simple "select ... from Voyages where voyageur=$pk" being $pk the item id, similar to what happens in the function prepareQuery) and builds a multi-dimensional array containing the data from the query.
C - Finally in the form (admin/views/voyageur/tmpl/voyageur_form.php I should add, inside the "foreach($fieldSet as $field)" a sort of :
if ($field->name == 'my_field'):
?>
<dt>
<?php echo $field->label; ?>
</dt>
<?php foreach($array as $v1) {
echo "<dd>";
foreach($v1 as $v2){
echo $v2 . " ";
}
echo "</dd>";
}
Where $array should be the multidimensional array output of the query obtained in B.
I understand there are a lot of lacking points (first of all voyagur_form.php does not know what $array is), but could you point me to the right places/files so to obtain the result ?
Thanks a lot
Elena