I got a view in my component's frontend, which catches data from model using the ID of the element:
protected function populateState($ordering = null, $direction = null)
{
$app = JFactory::getApplication();
$id = $app->input->get('id', null, 'int');
$this->setState('id', $id);
parent::populateState();
}
/**
* getItem function.
*
* @access public
* @param mixed $pk (default: null)
* @return void
*/
public function getItem($pk = null)
{
$pk = (!empty($pk)) ? $pk : (int) $this->getState('id');
...
return $this->_item[$pk];
}
Okay, this works fine, the model gets the data and the view is showing it.
Now I would like to create a form which saves the input of a user and attach it to the id.
So I created a form like this
<form id="save" class="form-validate" action="<?php echo JRoute::_('index.php?option=com_bestia'); ?>" method="post" >
...
<button type="submit" class="btn validate"><?php echo JText::_('COM_BESTIA_SUBMIT', true); ?>
<?php echo JHtml::_( 'form.token' ); ?>
<input type="hidden" name="task" value="item.save" />
</form>
I also created a hidden-field to add the id to the post-data
<field name = "id"
type = "hidden" />
But in my controller I can not access the id like this:
public function save($key = NULL, $urlVar = NULL)
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$jinput = JFactory::getApplication()->input;
$data = $jinput->get('jform', array(), 'post', 'array');
}
How can I submit the id to my controller?
JTable
,yourModelName.xml
for form inmodels/forms/
then in yourview.html.php
get form$this->form = $this->get('Form')
, get item$this->item = $this->get('Item')
and if form will not be filled just do$this->form->bind($this->item)
and all of the form will be in your scope of datajform
or otheras you wish in model->getForm()
method