Martin Kariuki Martin Kariuki - 7 days ago 5
PHP Question

Calling unknown method: frontend\models\NewsQuery::queryAll()

public function actionView($id)
{
$model = $this->findModel($id);
$related = News::find();
$related->andFilterWhere(['like', 'subject', $model->subject])
->orderBy(['id' => SORT_DESC])
->queryAll();

return $this->render('view', [
'model' => $model,'related'=>$related
]);
}


I get this error
Unknown Method – yii\base\UnknownMethodException
Calling unknown method: frontend\models\NewsQuery::queryAll()
Could someone tell me what I'm getting wrong?

Answer

Change it to:

public function actionView($id)
{
    $model = $this->findModel($id);
    $related = News::find();
    $related->andFilterWhere(['like', 'subject', $model->subject])
   ->orderBy(['id' => SORT_DESC]);

    return $this->render('view', [
        'model' => $model,'related' => $related->all()
    ]);
}