Php 错误:ProfileControllerSetting::cancel()的声明应与JControllerPerform::cancel($key=NULL)兼容

Php 错误:ProfileControllerSetting::cancel()的声明应与JControllerPerform::cancel($key=NULL)兼容,php,joomla2.5,Php,Joomla2.5,嘿,我是joomla的新手,正在制作一个名为profile的组件。文件夹控制器/setting.php中出现错误。 这是我的密码 类ProfileControllerSetting扩展JControllerPerform{ function save(){ parent::save(); if($this->task=='save') $this->setredirect('index.php?option=com_profile');

嘿,我是joomla的新手,正在制作一个名为profile的组件。文件夹控制器/setting.php中出现错误。 这是我的密码

类ProfileControllerSetting扩展JControllerPerform{

 function save(){
    parent::save();
    if($this->task=='save')     
    $this->setredirect('index.php?option=com_profile');
        }

 function cancel(){     
    $this->setredirect('index.php?option=com_profile');
  }

}
错误是:
严格标准:ProfileControllerSetting::cancel()的声明应与JControllerPerform::cancel($key=NULL)兼容。


请帮帮我。

你的解释器已经告诉你,你必须参数化你的功能。 尝试以下方法:

class ProfileControllerSetting extends JControllerForm { 
     public function save($key = NULL){
        parent::save();
        if($this->task=='save')     
        $this->setredirect('index.php?option=com_profile');
    }

     public function cancel($key = NULL, $urlVar = NULL){     
        $this->setredirect('index.php?option=com_profile');
    }
}

由于不能简单地重载PHP函数,因此您正在扩展类
JControllerForm
。因此,您必须遵循在中声明的函数load和save的定义。

对于Joomla 3.6方法,save必须有两个参数

public function save($key = NULL, $urlVar = NULL) {
    parent::save();
    if($this->task=='save')     
      $this->setredirect('index.php?option=com_profile');
}

您是否尝试将
NULL
添加为默认值?请查看我的答案,我刚刚编辑过。@R.J请耐心告诉我这是否有帮助。
public function save($key = NULL, $urlVar = NULL) {
    parent::save();
    if($this->task=='save')     
      $this->setredirect('index.php?option=com_profile');
}