E
E
Edward2017-07-29 15:25:31
Yii
Edward, 2017-07-29 15:25:31

How to make a selection from the database in yii2 using the rest api?

I use ActiveController as written in the documentation.

public function actionIndex()
    {
        $modelClass = $this->modelClass;        
        $developer = Developers::findOne([
            'id' => Yii::$app->request->get('developer_id'),
        ]);
        $complex_type = ComplexType::findOne([
            'id' => Yii::$app->request->get('complex_id'),
        ]);
        $complex = Complex::findOne([
            'type_id' => $complex_type->id,
            'developer_id' => $developer->id,
        ]);
        $query = $modelClass::find()
        ->where(
            [
                'amount_room' => Yii::$app->request->get('amount_room'),
                'yardage' => Yii::$app->request->get('yardage'),
                'level' => Yii::$app->request->get('level'),
                'complex_id' => $complex->id,
            ]);
        return new ActiveDataProvider([
            'query' => $query,
        ]);
    }

The question is: Now it is necessary to transfer all the parameters, which is logical in principle. How to make a check for the fullness of the parameter, and already, depending on this, do the search? I can do a bunch of if's, but it doesn't turn out very pretty. What is the best way to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-07-29
@slo_nik

Good evening.
Everything is told to the smallest detail.
www.elisdn.ru/blog/103/yii2-rest-api

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question