I'm developing my custom component for storing some records in the DB. In my #__records DB table there is the column attribs where I want to store some data in json-format like:
{"field1":"value1","field2":"value2"}
I try to add the input for the field1 in my admin/models/forms/record.xml like:
<fields name="attribs">
<fieldset name="basic">
<field name="field1" type="text" />
</fieldset>
</fields>
and I can render it in my admin/views/record/tmpl/default.php via foreach:
<?php foreach($this->form->getFieldset() as $field): ?>
<?php echo $field->input; ?>
<?php endforeach; ?>
Although at that the field1 hasn't its value that is already stored in the DB.
There are two questions:
1. How can I render the input in views/record/tmpl/default.php not via foreach but like:
echo $this->form->getInput('field1'); // it doesn't display the input at all
and with its stored value
2. How can I save new value of the field1 i.e. what code should I add to the save($data) function in my admin/models/record.php (or to JTable class)? I need something like:
public function save($data)
{
if(isset($data['attribs']) && isset($data['attribs']['field1']))
{
// what code should be here ???
}
return parent::save($data);
}