E
E
EVOSandru62015-02-24 03:04:25
Yii
EVOSandru6, 2015-02-24 03:04:25

How in yii to execute findAll in a model inherited from CActiveRecord?

Good afternoon.
Inherited ActiveRecord from CActiveRecord and in turn all models from ActiveRecord , so that all models have typical project-specific methods, for example, created such a method in ActiveRecord :

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

I call it from the controller:
public function actionIndex()
  {
        $model = Project::getAll();
        $this->render('index',array(
            'model'=>$model
        ));
}

I'm getting an error:
Fatal error: Using $this when not in object context in X:\home\ferrum\www\framework\db\ar\CActiveRecord.php on line 1469
Please help me find the connection.
...
It turned out when I made the method public, but I have to create an object in the controller, but I would like to handle it statically, are there any options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tatarin, 2015-02-24
@EVOSandru6

replace
with
self::model()->findAll($criteria);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question