[英]Redirect to the same form with data loaded - Joomla 2.5
我在Joomla 2.5中覆盖了SAVE()函数
class footballModelPlayer extends JModelAdmin {
public function getTable($type = 'Player', $prefix = 'footballTable', $config = array()) {
return JTable::getInstance($type, $prefix, $config);
}
public function save($data) {
// some code here
$table_one->bind($data);
$table_one->save($data);
return true;
}
问题是当我保存新数据或编辑现有数据时,它会将我重定向到“新空自”。
如果我通过return $data->player_id
替换最后一行,它将我重定向到装载数据的相同表单,但显示错误
Save failed with the following error:
我可以通过显示“成功消息”来保存/更新记录,并保持与加载数据的表单相同吗?
您的模型中缺少2个功能:
public function getForm($data = array(), $loadData = true){
// Get the form.
$form = $this->loadForm('com_football.Player', 'Player', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form))
{
return false;
}
return $form;
}
和
protected function loadFormData(){
$data = JFactory::getApplication()->getUserState('com_football.edit.Player.data', array());
if (empty($data))
{
$data = $this->getItem();
}
return $data;
}
实施它们,您的数据将神奇地出现。 顺便说一下,您不需要覆盖save方法,因为您正在执行默认情况下将要执行的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.