JForm on JPlatform 11.3: how to load data from multiple models/tables from a single view

443 views
Skip to first unread message

Emerson da Rocha Luiz

unread,
Dec 21, 2011, 3:25:03 AM12/21/11
to joomla-de...@googlegroups.com
Hi all,

Since version 1.5 of Joomla, things have improved to deal with form data, and it really is amazing what the JForm does. However, I need a help on how to do it to load data from a different ID pointed to by the $ _GET / $ _POST for cases in which I am not using just one form, i.e, where there is a relationship between the main table and related tables.

I will take as example HelloWorld Component from https://github.com/rvsjoen/joomla-tutorials/tree/master/part15

/admin/helloworld/tmpl/edit.txt,added:

<?php foreach($this->formCustom->getFieldset('details') as $field): ?>
<li><?php echo $field->label;echo $field->input;?></li>
<?php endforeach; ?>


/admin/helloworld/view.html.php, in display():


$form = $this->get('FormCustom');
$this->formCustom = $form;


/admin/models/helloworld.php, new method

public function getFormCustom($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_helloworld.custom', 'custom', array('control' => 'jformCustom', 'load_data' => $loadData));
return $form;
}

/admin/models/forms, new file

custom.xml


It works fine for print adicional forms on same view and make form names as jformCustom['fieldname'], and and manages well when fields have the same names of multiple forms when save it. But... the problem is thatI do not know how to override id which will be used to load data, and will load JForm will load same id. I see that I can chose which data will load editing loadFormData() from model, but... how to do it? Also, how to get last some field from last call and use on next loadFormData() and avoid overhead from another querie to database?


--
Emerson da Rocha Luiz
+55 51 9881-9146  | MSN: emerson at webdesign.eng.br | GTalk: fititnt at Gmail | Skype: fititnt | http://www.fititnt.org | Twitter: @fititnt
Membro do JUGRS | Membro do JCoderBR

JSamir

unread,
Jan 7, 2012, 4:17:41 AM1/7/12
to joomla-de...@googlegroups.com, eme...@webdesign.eng.br
Is using a plugin with the event onContentPrepareForm/onContentPrepareData an option for you?

Emerson da Rocha Luiz

unread,
Jan 7, 2012, 6:01:07 AM1/7/12
to joomla-de...@googlegroups.com
Humm, thanks Samir. Good to know about they.

Does anyone know an approach that I could do, which is equivalent to this, perhaps the model or controller? I got no problems in addition to accessing fields of different XMLs, but not on data from these popular items JForm populated with information from a different id from main form. I must be missing something fool.

Also, at least on CMS Core, did not find some example using a relationship in which an ID between two tables are different, and not just one field, but a whole group of form. This is especially useful when you have to centralize a group of related forms in a same screen.

Att. Emerson 

--
Emerson da Rocha Luiz
+55 51 9881-9146  | MSN: emerson at webdesign.eng.br | GTalk: fititnt at Gmail | Skype: fititnt | http://www.fititnt.org | Twitter: @fititnt
Membro do JUGRS | Membro do JCoderBR



Reply all
Reply to author
Forward
0 new messages