I'm writing a small Joomla component for my school but there is a little problem with it.
When I go to edit a record and then save it, instead of updating that record, it saves it as a new record with updated field.
I have checked the button in view for any mistakes, but can't see any issues.
Can any one please tell me some common mistakes that could cause this issue?
Controller
class StudentControllerStudent extends JControllerForm
{
public function __construct($config = array()) {
parent::__construct($config);
}
}
Model
class StudentModelStudent extends JModelAdmin
{
public function getTable($type = 'Student', $prefix = 'StudentTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
public function getForm($data = array(), $loadData = true) {
$form = $this->loadForm('com_student.student', 'student',array('control' => 'jform', 'load_data' => $loadData));
if (empty($form))
{
return false;
}
return $form;
}
protected function loadFormData() {
return $this->getItem();
}
}
view.html.php
class StudentViewStudent extends JViewLegacy {
protected $state;
protected $item;
protected $form;
/**
* Display the view
*/
public function display($tpl = null) {
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
throw new Exception(implode("\n", $errors));
}
$this->addToolbar();
parent::display($tpl);
}
protected function addToolbar() {
JFactory::getApplication()->input->set('hidemainmenu', true);
JToolbarHelper::title('edit item');
JToolbarHelper::save('student.save');
if (empty($this->item->id))
{
JToolbarHelper::cancel('student.cancel');
}
else
{
JToolbarHelper::cancel('student.cancel', 'JTOOLBAR_CLOSE');
}
}
}
&layout=edit
?adminstartor/com_user/views/user/view.html.php
andadministrator/com_user/models/user.php
for better reference.