【问题标题】:Error:Declaration of ProfileControllerSetting::cancel() should be compatible with JControllerForm::cancel($key = NULL)错误:ProfileControllerSetting::cancel() 的声明应该与 JControllerForm::cancel($key = NULL) 兼容
【发布时间】:2013-10-07 08:23:38
【问题描述】:

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

类 ProfileControllerSetting 扩展 JControllerForm {

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

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

}

来的错误是:Strict Standards: Declaration of ProfileControllerSetting::cancel() should be compatible with JControllerForm::cancel($key = NULL)

Strict Standards: Declaration of ProfileControllerSetting::save() should be compatible with JControllerForm::save($key = NULL, $urlVar = NULL) 

请帮帮我。

【问题讨论】:

    标签: php joomla2.5


    【解决方案1】:

    你的解释器已经告诉你了,你必须参数化你的函数。 尝试类似:

    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。所以你必须遵循JControllerForm中声明的函数load和save的定义。

    【讨论】:

    • 您是否尝试将NULL 添加为默认值?看看我的答案,我刚刚编辑过。
    • @R.J 请耐心等待是否有帮助。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-13
      • 2017-11-07
      • 2018-01-17
      • 1970-01-01
      相关资源
      最近更新 更多