【问题标题】:Getting an error like this in cake php [duplicate]在cake php中出现这样的错误[重复]
【发布时间】:2013-07-18 16:41:12
【问题描述】:
Declaration of UtilityBehavior::beforeDelete() should be compatible with ModelBehavior::beforeDelete(Model $model, $cascade = true)

我在加载一个控制器时收到此错误,但它在任何其他控制器中都不存在。

这是 Term 控制器中唯一的删除操作

public function admin_delete($id = null) {
        if (!$this->request->is('post')) {
            throw new MethodNotAllowedException();
        }
        $this->Term->id = $id;
        if (!$this->Term->exists()) {
            throw new NotFoundException(__('Invalid term'));
        }
        if ($this->Term->delete()) {
            $this->Session->setFlash(__('Term deleted'));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('term was not deleted'));
        $this->redirect(array('action' => 'index'));
    }

控制器是术语控制器

【问题讨论】:

  • 消息告诉你问题出在哪里!您显然在您正在加载的模型中声明了 beforeDelete()(Car 或 Term 查看您的控制器代码),该模型具有与基本模型的 beforeDelete() 方法不同的参数。
  • @MartinBean: Term 模型文件中没有 beforeDelete(),抱歉,汽车打错了

标签: php cakephp


【解决方案1】:

修复行为方法的声明。如果可能,也将正确的版本提交给插件的维护者(如果不是你的话)。

正如错误消息中已经提到的,应该是

public function beforeDelete(Model $model, $cascade = true) {}

你的可能只是

public function beforeDelete(Model $model) {}

等等

【讨论】:

  • 感谢它修复了它。因为我对蛋糕很陌生,并且正在使用其他人编写的现有代码库。但是为什么其他控制器没有出现此错误?
  • 你没有使用那里的行为(使用=加载)。
猜你喜欢
  • 1970-01-01
  • 2016-01-20
  • 2017-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-29
  • 1970-01-01
相关资源
最近更新 更多