L
L
limpompo2019-05-12 23:23:20
Yii
limpompo, 2019-05-12 23:23:20

It throws an error when executing the search function, what's the problem?

Search function code

public function actionSearch(){
        $q = Yii::$app->request->get('q');
        $query = Product::find()->where(['like', 'name', $q]);
        $pages = new Pagination(['totalCount' => $query->count(), 'pageSize'=>3,'forcePageParam' => false, 'pageSizeParam' => false]);
        $products = $query->offset($pages->offset)->limit($pages->limit)->all();
        return $this->render('search', compact('products','pages','q'));
    }

Screenshot of the error: fvKblsi.png
If you access the variable q in the 3rd line through quotes, then the request is not correct
tVbfuBI.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lander, 2019-05-12
@limpompo

Apparently Yii::$app->request->get('q') == null.
That is, the $q variable is either null, or false, or something else that is undefined.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question