Yii Framework Forum: Chapter 6 Page 131 - Missing Argument 1 For Projectcontroller::loadmodel() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 6 Page 131 - Missing Argument 1 For Projectcontroller::loadmodel()

#1 User is offline   Sandy Rig 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-September 12

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,
));
}
0

#2 User is offline   Reza m 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 148
  • Joined: 07-March 12

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,
));
}





0

#3 User is offline   Sandy Rig 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-September 12

Posted 30 September 2012 - 11:34 PM

Thankyou Reza but now I get a 404.

Error 404

The requested page does not exist.

0

#4 User is offline   Reza m 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 148
  • Joined: 07-March 12

Posted 01 October 2012 - 04:10 AM

View PostSandy 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.



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
0

#5 User is offline   Sandy Rig 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-September 12

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.
0

#6 User is offline   Reza m 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 148
  • Joined: 07-March 12

Posted 01 October 2012 - 09:25 AM

View PostSandy 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
0

#7 User is offline   Sandy Rig 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-September 12

Posted 02 October 2012 - 03:00 AM

View PostReza m, on 01 October 2012 - 09:25 AM, said:

I think you simply don't have a project with id 1 in your database, check your db


I have two projects in projects table with IDs 1 and 2.
0

#8 User is offline   quokka 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 08-November 12
  • Location:Melbourne, Australia

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users