Is it possible to create a master model using CActiveRecord the same as the Yii "Controller" from which all other models extend from?
So …
Model extends CActiveRecord
TestOne extends Model
TestTwo extends Model
etc.
Is it possible to create a master model using CActiveRecord the same as the Yii "Controller" from which all other models extend from?
So …
Model extends CActiveRecord
TestOne extends Model
TestTwo extends Model
etc.
Yes, I do this in my application.
CActiveRecord -> ExCActiveRecord -> ActualModels
You can set the gii tool to point at your base class. (I called mine Ex… as Extension.) I use it for things like primary key caching, date conversion behaviors etc.
Ahh yes, I tried doing it the normal way and extending it, however it complains about the "constructor" in the "ExCActiveRecord" model?
Did you have this problem?
do not use constructor, use the init method
constructor method is used internally by yii
Ok, so use the init method in the "ExActiveRecord" model, yes?
In your config/main.php
‘components’=>array(
… //other items
‘user’ => array(‘class’ => ‘ExCWebUser’)
)
You can then access it through Yii::app()->user
Ok,
So I do this in the "components" folder.
class ExActiveRecord extends ActiveRecord {
}
No constructor for the SuperModel???
And this is my normal model.
class User extends ExActiveRecord {
public static function model($className = __class__) {
return parent::model($className);
}
}
Is that correct???
And then I set the thing you said in the config and it will work???
You can use the method init if you need, that is called after yii uses construct
Exactly
yes