gpt4 book ai didi

yii - 如何扩展 CMssqlCommandBuilder 并在模型中使用扩展类

转载 作者:行者123 更新时间:2023-12-04 16:00:19 24 4
gpt4 key购买 nike

我正在使用 YIIMSSQL

尝试使用分页时 CMssqlCommandBuilder 出现问题。我在 http://code.google.com/p/yii/issues/detail?id=1501 处使用了 comment#7 中给出的代码

我编辑了 CMssqlCommandBuilder,我的代码运行良好。

现在的问题是我不想更改 YiiCMssqlCommandBuilder 类 我想从 CMssqlCommandBuilder 扩展一个类并使用那个类。

如何告诉我的模型类使用新的扩展类而不是 CMssqlCommandBuilder

最佳答案

在扩展 CActiveRecord 的基础模型类中覆盖 getCommandBuilder()http://www.yiiframework.com/doc/api/1.1/CActiveRecord#getCommandBuilder-detail

class MyActiveRecord extends CActiveRecord
{
public function getCommandBuilder()
{
return new MyMssqlCommandBuilder($this->getDbConnection()->getSchema());
}
}

虽然不确定这样做是否是“正确的方法”。

我这样做可能更合适:

class MyActiveRecord extends CActiveRecord
{
private $_builder;
public function getCommandBuilder()
{
if($this->_builder!==null)
return $this->_builder;
else
return $this->_builder = new MyMssqlCommandBuilder($this->getDbConnection()->getSchema());
}
}

关于yii - 如何扩展 CMssqlCommandBuilder 并在模型中使用扩展类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13179218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com