php - ArgumentCountError in Yii 2
Get the solution ↓↓↓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,
]);
}
Answer
Solution:
You don't need to fetch the data forActiveDataProvider
, 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 isfindAll()
expects a condition and will return results, not anActiveQuery
instance.
e.g.
Coursecontent::findAll(['coursecontent_id' => $id]);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: integrity constraint violation: 1452 cannot add or update a child row: a foreign key constraint fails
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.