Page 1 of 1
Chapter 6 Page 131 - Missing Argument 1 For Projectcontroller::loadmodel()
#1
Posted 28 September 2012 - 07:38 AM
Hello,
I am new to yii and following the Agile web development book. I have followed all the instructions so far and had no problem until then end of page 131.
I get this warning
Missing argument 1 for ProjectController::loadModel(), called in C:\wamp\www\trackstar\protected\controllers\ProjectController.php on line 56 and defined
/**
* Displays a particular model.
*/
public function actionView()
{
$issueDataProvider=new CActiveDataProvider('Issue', array(
'criteria'=>array(
'condition'=>'project_id=:projectId',
'params'=>array(':projectId'=>$this->loadModel()->id), //This is line 56
),
'pagination'=>array(
'pageSize'=>1,
),
));
$this->render('view',array(
'model'=>$this->loadModel(),
'issueDataProvider'=>$issueDataProvider,
));
}
I am new to yii and following the Agile web development book. I have followed all the instructions so far and had no problem until then end of page 131.
I get this warning
Missing argument 1 for ProjectController::loadModel(), called in C:\wamp\www\trackstar\protected\controllers\ProjectController.php on line 56 and defined
/**
* Displays a particular model.
*/
public function actionView()
{
$issueDataProvider=new CActiveDataProvider('Issue', array(
'criteria'=>array(
'condition'=>'project_id=:projectId',
'params'=>array(':projectId'=>$this->loadModel()->id), //This is line 56
),
'pagination'=>array(
'pageSize'=>1,
),
));
$this->render('view',array(
'model'=>$this->loadModel(),
'issueDataProvider'=>$issueDataProvider,
));
}
#2
Posted 28 September 2012 - 09:13 AM
loadModel method needs an id to return a model and actionView method needs it too so you can modify your code as follow
public function actionView($id)
{
$issueDataProvider=new CActiveDataProvider('Issue', array(
'criteria'=>array(
'condition'=>'project_id=:projectId',
'params'=>array(':projectId'=>$this->loadModel($id)->id), //you can pass $id directly (loadModel method is not necessary here!)
),
'pagination'=>array(
'pageSize'=>1,
),
));
$this->render('view',array(
'model'=>$this->loadModel($id),
'issueDataProvider'=>$issueDataProvider,
));
}
#3
Posted 30 September 2012 - 11:34 PM
Thankyou Reza but now I get a 404.
Error 404
The requested page does not exist.
Error 404
The requested page does not exist.
#4
Posted 01 October 2012 - 04:10 AM
Sandy Rig, on 30 September 2012 - 11:34 PM, said:
Thankyou Reza but now I get a 404.
Error 404
The requested page does not exist.
Error 404
The requested page does not exist.
view is to show database data by using id and your url should look like this (according to book):
localhost/tasctrak/index.php?r=project/view&id=1
so if you try to retrive a data that doesn't exist in your db, you get 404 error
#5
Posted 01 October 2012 - 08:48 AM
The URL is correct. I am using the same URL. There are 2 projects and there is 1 issue attached to each project by following the whole procedure in the book. I have re-checked the code many times, it all looks to be correct. I think may be I missed some thing but I cant figure out what.
#6
Posted 01 October 2012 - 09:25 AM
Sandy Rig, on 01 October 2012 - 08:48 AM, said:
The URL is correct. I am using the same URL. There are 2 projects and there is 1 issue attached to each project by following the whole procedure in the book. I have re-checked the code many times, it all looks to be correct. I think may be I missed some thing but I cant figure out what.
I think you simply don't have a project with id 1 in your database, check your db
#8
Posted 13 November 2012 - 12:34 AM
See this other topic in this forum with resolution of the same issue:
http://www.yiiframew...k-at-chapter-6/
Appears to be due to a change in the framework between the version the book was written for, and later versions.
http://www.yiiframew...k-at-chapter-6/
Appears to be due to a change in the framework between the version the book was written for, and later versions.
Share this topic:
Page 1 of 1

Help












