如何在 CakePHP 中正确覆盖模型的构造函数 [英] How to override model's constructor correctly in 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
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屋!