Undefined variable issue on the first Yii app.

I have successfully set-up Yii following the documentation with the page loading but I am unable to get running the first step in the first Yii app found in the cookbook.

I am getting the error: Undefined variable: pages

in file: /home/developer/yii-first/protected/views/user/list.php(8)

Referring to line 8: 00008: $this->widget('CLinkPager',array('pages'=>$pages));

This is on the home page. The home page is fine as soon as I revert /protected/views/site/index.php back to how it was originally.

Any ideas?

Thanks,

Dubby.

Did you change your SiteController.php?

Thanks for the reply.

I have just followed the installation at:

http://www.yiiframew…rt.installation AND

http://www.yiiframew…start.first-app

which includes:

Running yiic webapp (from which the basic template site runs ok)

Modifying /protected/config/main.php to include the database parameters

Created the database and User table.

Running 'model User' and 'crud User'

The site works at each step along here fine.

I didn't see any mention of changing SiteController.php

From this base install I started following the tutorial here: http://www.yiiframew…doc/cookbook/5/ but at the first step of replacing the contents of file /protected/views/site/index.php created the ‘undefined variable: page’ error.

The cookbook page does not apply because the user list view requires $pages. You may refer to UserController::actionList() to see how to provide this variable.

I'm sorry but I still don't follow.

The cookbook page does not apply to what?

The cookbook example that I am trying needs User and User needs $pages. It seems that there is a step I overlooked somewhere that I cannot find.

Edit: I looked into UserController::actionList() but wasn't sure what to do. I am just starting out with Yii and I have read through the definitive guide but am trying to learn from from these exercises so am quite naive at this time.

The view "/user/list" was originally designed to be used by the "list" action in the UserController, which will supply a $pages variable to the view. The cookbook page tries to reuse this view in the "index" action of SiteController.

I recommend you follow the blog demo to learn Yii, instead of cookbook. The latter is meant to solve individual problem that you encounter during your development.

Thanks again qiang.

Is there a tutorial for the Blog? I have found links to the blog demo itself and the SVN repository but not an explanation of how it works.

A tutorial is coming in the next few days.