Hi there,
I would like to provide to all my model classes an easy function to load a model which would be defined in my ownd ActiveRecord class like this:
class ActiveRecord extends CActiveRecord{
public static function load($id) {
$model = self::model()->findByPk($id);
if ($model === null)
throw new CHttpException(404, 'The requested page does not exist.');
return $model;
}
}
all my models would extend that class:
class MyModel extends ActiveRecord{
public static function model($className = __CLASS__) {
return parent::model($className);
}
}
The problem is that when I call MyModel::load($id) the code fails all the time in the model() method of CActiveRecord. The wrong class name is passed:
"Fatal error: Cannot instantiate abstract class CActiveRecord in C:\xampp\htdocs\yii\framework\db\ar\CActiveRecord.php on line 386"
This is because "self::model()" in load() applies to ActiveRecord and not the MyModel class. Basically the model() function of MyModel is never called.
It seems an easy task but I can’t find a work around. Any idea or alternative solution?
Thanks
Renaud