简体   繁体   English

重定向到加载数据的相同表单-Joomla 2.5

[英]Redirect to the same form with data loaded - Joomla 2.5

I have overridden the SAVE() function in 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;
}

Problem is the when I save the new data or edit the existing one, it redirects me to the New Empty From. 问题是当我保存新数据或编辑现有数据时,它会将我重定向到“新空自”。

If I replace last line by return $data->player_id it redirects me to the same form loaded with data but show error 如果我通过return $data->player_id替换最后一行,它将我重定向到装载数据的相同表单,但显示错误

Save failed with the following error: 

Hoe can I save/update the records with displaying Successful Message and staying on the same form with data loaded into it??? 我可以通过显示“成功消息”来保存/更新记录,并保持与加载数据的表单相同吗?

You are missing 2 functions in your model: 您的模型中缺少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;

 }

and

protected function loadFormData(){
    $data = JFactory::getApplication()->getUserState('com_football.edit.Player.data', array());
    if (empty($data)) 
    {
        $data = $this->getItem();
    }
    return $data;
}

Implement them and your data will magically appear. 实施它们,您的数据将神奇地出现。 You don't need to override the save method by the way, since you are doing what will be done by default. 顺便说一下,您不需要覆盖save方法,因为您正在执行默认情况下将要执行的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM