A
A
andr20172016-11-01 17:11:04
Yii
andr2017, 2016-11-01 17:11:04

Where is the best place to specify the condition?

Through the GET parameter, a condition is passed by which the value should be filtered. These values ​​are cleared and stored in the model, then the data is retrieved using these conditions.
Where is it correct to specify the conditions (status, ko_from), in separate methods, or leave it like that?
Model method:

public function getActiveTransfers() {
        $criteria = new CDbCriteria();
        $criteria->with = ['good', 'koFrom', 'koTo'];

        $criteria->condition .= 'status <> '.self::STATUS_RECD;

        if($this->status)
            $criteria->condition .= ' AND status ='.$this->status;

        if($this->ko_from)
            $criteria->condition .= ' AND ko_from ='.$this->ko_from;


        return $this->getCActiveDataProvider($criteria);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-11-07
@webinar

From the point of view of code reuse, of course, it is better to put it into the methods of the model, but if this selection is used 1 time, then this is also quite normal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question