Joomla Asked by user2363969 on September 5, 2021
I hope that I may ask this, but is there a straight forward code example for a subform to save the data and to retrieve the data.
What I have now is written an save function in controller/model with an insert statement to save the data and I’m thinking what is the best way to populate the edit.php with data. I can write an select query to get the data but I think this is not the way.
And I’m not the only one who strugling with this I think.
BR.
Nico
I have it now working for a week. Someone give me an example and it is simpler than I thought! And I was on the wrong track.
I read on some forums about a heading- and a Child table. My mindset about a heading- and child table that these are two 'physical' different tables related to each other by a foreign key. If I understand now, this is not the idea behind it. It is one table with 'main' data and a field with 'child' data saved as JSON format.
Than an second important thing the field in that table MUST have the SAME name as the subform name!! Otherwise the data is not saved and you don't get an error message!
The subform is good to use for let say a floor (heading) - room (child) relation. I thing it is hard to use if you have table without a heading-child relation, but just simple config-data. I thought it is nice to use in this case as well because you don't have to fill in one value and press every time 'save-new'. With a subform it is more user friendly IMHO, you press the '+' sign and add a value.
In the 'example' I received the function check() ('tables'.php) added with the line:
function check() {
//You can add here more as filling created_by etc.
$this->subformname = json_encode($this->subformname);
}
Were the function check come from, I don't know, but works
And at the edit.php you can simply add:
echo $this->form->renderField('subformname');
I hope that I have not forgotten something but than it works.
Except of the edit.php line, I was not AWARE of this these things and I could not find something about these specific issue's! I was on a way to make my own 'save' function for the controller and model. But after some hours in some days, I thought this can't be idea behind it, because it is a joomla field so it should more or less work out of the box, but how does this work!???
Therefore it should be nice if there is simple straightforward tutorial or example, so that someone can see that it works or at least it gives you the idea that it works! further I don't ask anything from anyone.
I'm not asking from you or anyone else to make a specific example or tutorial for me but maybe you know were I can find this important example/tutorial. And I don't know were mickmackusa has found these fundamental information, but if you can point me to this, than I feel bad.
And if you can point me to this information maybe you can point me also to the info were is explained what the functionality is and when should use it about:
And otherwise, I hope that I will come along this information while I'm searching for something else.
BR.,
Nico
Answered by user2363969 on September 5, 2021
Subform data is passed as an array. To store it in database you have to convert it to a string such as JSON. How and where to do this depends on how your component is written. But if your component uses Table API, you can add support for JSON encoded fields by declaring $_jsonEncode
class property in the table class:
class MyTable extends JTable
{
protected $_jsonEncode = ['subform_field', 'another_subform_field'];
}
Answered by Sharky on September 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP