E
E
EVOSandru62015-02-24 08:57:39
Yii
EVOSandru6, 2015-02-24 08:57:39

How to correctly inherit from CActiveRecord in Yii?

Good afternoon,
There is a table ActiveRecord derived from CActiveRecord . From the first I inherited all the models. In ActiveRecord , the only method is:

static function getAll(){
        $criteria = new CDbCriteria();
        $criteria->condition = 'EXIST = 1';
        return self::model()->findAll($criteria);
    }

There is a Project model that inherits ActiveRecord :
It has a standard method that has been claimed on many forums to solve my problem
public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

When I call a method in ProjectController:
public function actionIndex()
  {
        $model = Project::getAll();
        $this->render('index',array(
            'model'=>$model
        ));
}

I catch the error:
Fatal error: Cannot instantiate abstract class CActiveRecord in X:\home\ferrum\www\framework\db\ar\CActiveRecord.php on line 395
It seems that the error occurs when this line is called: Please help!
return self::model()->findAll($criteria);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vit, 2015-02-24
@EVOSandru6

Try
Or make getAll non-static:

public function getAll(){
        $criteria = new CDbCriteria();
        $criteria->condition = 'EXIST = 1';
        return $this->findAll($criteria);
    }

And use like this:
Project::model()->getAll();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question