Reputation: 81
I have created 3 course contents. But unfortunately, it only shows 1 course content as what the picture showed below. What I am trying to do is to show ALL the course content that I created earlier. It runs normal when I run with this syntax.
public function actionView($id)
{
$dataProvider = new ActiveDataProvider([
'query' => Coursecontent::findAll()->andFilterWhere(['coursecontent_id' => $id]),
]);
return $this->render('view', [
'model' => $this->findModel($id), 'dataProvider' => $dataProvider,
]);
}
But when I changed my code to this. It shows this error message. What i am trying to do here is to show all the course contents. Too few arguments to function yii\db\BaseActiveRecord::findAll(), 0 passed in D:\XAMPP\htdocs\valuefarm\algobox_admin\controllers\CourseController.php on line 57 and exactly 1 expected
public function actionView($id)
{
$dataProvider = new ActiveDataProvider([
'query' => Coursecontent::findAll()->andFilterWhere(['coursecontent_id' => $id]),
]);
return $this->render('view', [
'model' => $this->findModel($id), 'dataProvider' => $dataProvider,
]);
}
Upvotes: 0
Views: 1499
Reputation: 2122
You don't need to fetch the data for ActiveDataProvider
, it will do it for you.
Just provide the query.
public function actionView($id)
{
$dataProvider = new ActiveDataProvider([
'query' => Coursecontent::find()->andFilterWhere(['coursecontent_id' => $id]),
]);
return $this->render('view', [
'model' => $this->findModel($id), 'dataProvider' => $dataProvider,
]);
}
Your error is findAll()
expects a condition and will return results, not an ActiveQuery
instance.
e.g.
Coursecontent::findAll(['coursecontent_id' => $id]);
Upvotes: 1