3

で使用YIIしていますMSSQL

ページネーションを使用しようとしたときに問題が発生しましCMssqlCommandBuilderた。http://code.google.com/p/yii/issues/detail?id=1501にあるコードを使用しましcomment#7

を編集したところCMssqlCommandBuilder、コードが正常に機能しました。

Yii今の問題は、クラスを拡張したいのCMssqlCommandBuilderクラスを変更したくないので、CMssqlCommandBuilder代わりにそのクラスを使用することです。

モデル クラスに の代わりに新しい拡張クラスを使用するように指示するにはどうすればよいCMssqlCommandBuilderですか?

4

1 に答える 1

1

getCommandBuilder()CActiveRecord を拡張する基本モデル クラスで を 上書きします。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());
    }
}
于 2012-11-01T16:20:18.100 に答える