2012-11-01 30 views
3

嘗試使用分頁時,我使用YIIMSSQL如何延長CMssqlCommandBuilder和使用擴展的類模型

有一個問題CMssqlCommandBuilder。 我使用comment#7http://code.google.com/p/yii/issues/detail?id=1501

給出的代碼我編輯了CMssqlCommandBuilder和我的代碼工作正常。

現在的問題是我不想更改YiiCMssqlCommandBuilder類我想從CMssqlCommandBuilder擴展一個類並改爲使用該類。

如何告訴我的模型類使用新的擴展類而不是CMssqlCommandBuilder

回答

1

在擴展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()); 
    } 
} 
+0

謝謝你的職位@jborch。它完成了這項工作。 – Arif