Error Message -Chapter 6 of Agile Web App Dev with Yii 1.1.

I’m working on chapter 6 (around page 129) of the book Agile Web Development with Yii 1.1 and PHP5. I’m also using the code downloaded from PacktPub, but I’ve run into a problem (error message) that I don’t know how to solve.

I’m at the part of the book where we’re displaying the issues associated with each project on that page. The author gives us this code


/** * Displays a particular model. */

public function actionView() {

}

$issueDataProvider=new CActiveDataProvider('Issue', array( 'criteria'=>array(

'condition'=>'project_id=:projectId',

'params'=>array(':projectId'=>$this->loadModel()->id), ),

'pagination'=>array( 'pageSize'=>1,

), ));

$this->render('view',array( 'model'=>$this->loadModel(), 'issueDataProvider'=>$issueDataProvider,

));

and then this to actually display it


<br> <h1>Project Issues</h1>

<?php $this->widget('zii.widgets.CListView', array( 'dataProvider'=>$issueDataProvider, 'itemView'=>'/issue/_view',

)); ?>

as well as some changes to /protected/views/issue/_view. to get the layout

However, when I click on the project id number, I’m getting this error message. Does anyone know what’s gone wrong?

As mentioned, I’m using code supplied by the publisher, so I don’t see where I’ve made an error.




PHP Error


Missing argument 1 for ProjectController::loadModel(), called in /Applications/MAMP/htdocs/trackstar/protected/controllers/ProjectController.php on line 56 and defined


/Applications/MAMP/htdocs/trackstar/protected/controllers/ProjectController.php(167)


155             $model->attributes=$_GET['Project'];

156 

157         $this->render('admin',array(

158             'model'=>$model,

159         ));

160     }

161 

162     /**

163      * Returns the data model based on the primary key given in the GET variable.

164      * If the data model is not found, an HTTP exception will be raised.

165      * @param integer the ID of the model to be loaded

166      */

167     public function loadModel($id)

168     {

169         $model=Project::model()->findByPk((int)$id);

170         if($model===null)

171             throw new CHttpException(404,'The requested page does not exist.');

172         return $model;

173     }

174 

175     /**

176      * Performs the AJAX validation.

177      * @param CModel the model to be validated

178      */

179     protected function performAjaxValidation($model)



Here is the stack trace


Stack Trace

#0	

–  /Applications/MAMP/htdocs/trackstar/protected/controllers/ProjectController.php(56): ProjectController->loadModel()

51     public function actionView()

52     {

53         $issueDataProvider=new CActiveDataProvider('Issue', array(

54             'criteria'=>array(

55                  'condition'=>'project_id=:projectId',

56                  'params'=>array(':projectId'=>$this->loadModel()->id),

57              ),

58              'pagination'=>array(

59                  'pageSize'=>1,

60              ),

61          ));

#1	

+  /Applications/MAMP/htdocs/framework/web/actions/CInlineAction.php(50): ProjectController->actionView()

#2	

+  /Applications/MAMP/htdocs/framework/web/CController.php(300): CInlineAction->runWithParams(array("id" => "1"))

#3	

+  /Applications/MAMP/htdocs/framework/web/filters/CFilterChain.php(133): CController->runAction(CInlineAction)

#4	

+  /Applications/MAMP/htdocs/framework/web/filters/CFilter.php(41): CFilterChain->run()

#5	

+  /Applications/MAMP/htdocs/framework/web/CController.php(1122): CFilter->filter(CFilterChain)

#6	

+  /Applications/MAMP/htdocs/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(CFilterChain)

#7	

+  /Applications/MAMP/htdocs/framework/web/filters/CFilterChain.php(130): CInlineFilter->filter(CFilterChain)

#8	

+  /Applications/MAMP/htdocs/framework/web/CController.php(283): CFilterChain->run()

#9	

+  /Applications/MAMP/htdocs/framework/web/CController.php(257): CController->runActionWithFilters(CInlineAction, array("accessControl"))

#10	

+  /Applications/MAMP/htdocs/framework/web/CWebApplication.php(328): CController->run("view")

#11	

+  /Applications/MAMP/htdocs/framework/web/CWebApplication.php(121): CWebApplication->runController("project/view")

#12	

+  /Applications/MAMP/htdocs/framework/base/CApplication.php(155): CWebApplication->processRequest()

#13	

–  /Applications/MAMP/htdocs/trackstar/index.php(13): CApplication->run()

08 defined('YII_DEBUG') or define('YII_DEBUG',true);

09 // specify how many levels of call stack should be shown in each log message

10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

11 

12 require_once($yii);

13 Yii::createWebApplication($config)->run();

2011-05-29 01:05:03 Apache/2.0.64 (Unix) PHP/5.3.5 DAV/2 Yii Framework/1.1.7

Application Log

Timestamp	Level	Category	Message

01:05:03.010184	trace	system.CModule	

Loading "log" application component

in /Applications/MAMP/htdocs/trackstar/index.php (13)

01:05:03.010663	trace	system.CModule	

Loading "request" application component

in /Applications/MAMP/htdocs/trackstar/index.php (13)

01:05:03.010891	trace	system.CModule	

Loading "urlManager" application component

in /Applications/MAMP/htdocs/trackstar/index.php (13)

01:05:03.013011	trace	system.web.filters.CFilterChain	

Running filter ProjectController.filteraccessControl()

in /Applications/MAMP/htdocs/trackstar/index.php (13)

01:05:03.013236	trace	system.CModule	

Loading "user" application component

in /Applications/MAMP/htdocs/trackstar/index.php (13)

01:05:03.013421	trace	system.CModule	

Loading "session" application component

in /Applications/MAMP/htdocs/trackstar/index.php (13)

01:05:03.013964	error	php	

Missing argument 1 for ProjectController::loadModel(), called in

/Applications/MAMP/htdocs/trackstar/protected/controllers/ProjectController.php

on line 56 and defined

(/Applications/MAMP/htdocs/trackstar/protected/controllers/ProjectController.php:167)

Stack trace:

#0 /Applications/MAMP/htdocs/framework/web/CController.php(300):

CInlineAction->runWithParams()

#1 /Applications/MAMP/htdocs/framework/web/filters/CFilterChain.php(133):

ProjectController->runAction()

#2 /Applications/MAMP/htdocs/framework/web/filters/CFilter.php(41):

CFilterChain->run()

#3 /Applications/MAMP/htdocs/framework/web/CController.php(1122):

CAccessControlFilter->filter()

#4 /Applications/MAMP/htdocs/framework/web/filters/CInlineFilter.php(59):

ProjectController->filterAccessControl()

#5 /Applications/MAMP/htdocs/framework/web/filters/CFilterChain.php(130):

CInlineFilter->filter()

#6 /Applications/MAMP/htdocs/framework/web/CController.php(283):

CFilterChain->run()

#7 /Applications/MAMP/htdocs/framework/web/CController.php(257):

ProjectController->runActionWithFilters()

#8 /Applications/MAMP/htdocs/framework/web/CWebApplication.php(328):

ProjectController->run()

#9 /Applications/MAMP/htdocs/framework/web/CWebApplication.php(121):

CWebApplication->runController()

#10 /Applications/MAMP/htdocs/framework/base/CApplication.php(155):

CWebApplication->processRequest()

#11 /Applications/MAMP/htdocs/trackstar/index.php(13):

CWebApplication->run()

REQUEST_URI=/trackstar/index.php/project/1

in

/Applications/MAMP/htdocs/trackstar/protected/controllers/ProjectController.php

(167)

in

/Applications/MAMP/htdocs/trackstar/protected/controllers/ProjectController.php

(56)

in /Applications/MAMP/htdocs/trackstar/index.php (13)

01:05:03.014115	trace	system.CModule	

Loading "errorHandler" application component

in

/Applications/MAMP/htdocs/trackstar/protected/controllers/ProjectController.php

(167)

in

/Applications/MAMP/htdocs/trackstar/protected/controllers/ProjectController.php

(56)

in /Applications/MAMP/htdocs/trackstar/index.php (13)

Hi mjmitche,

For future reference,the proper place to discuss anything that concerns the book is here

Anyway, I think the ‘model’=>$this->loadModel() lacks the parameter. As you can see in ProjectController.php, loadModel is expecting an $id to be passed to it. I’m not sure where to get the $id though,sorry.

Maybe visit the book discussion section, most likely it was already discussed there. Read the identified issues thread by the author first. :)

This problem has been fixed on another thread. Sorry.

http://www.yiiframework.com/forum/index.php?/topic/12990-got-stuck-at-chapter-6/

Hi mjmitche,

Glad you found the fix!

Happy Yii-ing!

NOTE: moved to proper sub-forum…