如何在CakePHP中正确覆盖模型的构造函数 [英] How to override model's constructor correctly in CakePHP

查看:161
本文介绍了如何在CakePHP中正确覆盖模型的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CakePHP 2.0中测试模型时遇到麻烦,似乎问题出在模型的构造函数上。

I have troubles with testing Model in CakePHP 2.0 and it seems the problem is on the model's constructor.

public function __construct(){
    parent::__construct(); 
    $this->_pagi_cuantos = 2;
}

即使我删除了所有内容,测试。

Even if I delete all its content, I still getting problems trying to run the test.

Mark Story告诉我:

Mark Story told me:


如果您有建构函式'正确重写构造函数

if you have a constructor make sure you're overriding the constructor correctly. Failing to do so will cause errors like this.


推荐答案

为什么不看核心代码
它的开源毕竟:
https://github.com/cakephp/cakephp/blob/2.1/lib/Cake/Model/Model.php#L653 < a>

why don't you look into the core code its open source after all: https://github.com/cakephp/cakephp/blob/2.1/lib/Cake/Model/Model.php#L653

所有您的模型:

public function __construct($id = false, $table = null, $ds = null) {
    parent::__construct($id, $table, $ds);
}

这篇关于如何在CakePHP中正确覆盖模型的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆