Chapter 7 problem

Dear all,

I am new to the forum and I hit an odd error and hope for your help here.

At the beginning of chapter 7, I changed my createProject() content to




        //create a new project

        $newProject = new Project;

        $newProjectName = 'Test Project Creation';

        $newProject->setAttributes(

                array(

                    'name' => $newProjectName,

                    'description' => 'This is a test for new project creation',

                )

            );

        //set the application user id to the first users in our fixtures data

        Yii::app()->user->setId($this->user('user1')->id);

        $this->assertTrue($newProject->save());



When i ran the test, I had an error:

Exception: Unknown method ‘user’ for class ‘ProjectTest’.

at the line of Yii::app()->user->setId($this->user(‘user1’)->id);

I figure this could be the Yii:app() in my development environment was not set up correctly. I found in main.php there is a series of parameter that already set for the app and you can access these for example Yii:app()->name would return ‘My Web Application’. However I cant find where the user variable is created for Yii::app() and how I could set it.

Please give me sone hints on this, or if i missed something previously set up in the book please point it out for me,

Thanks a lot for your help

Tri

try to change Yii::app()->user->setId($this->user(‘user1’)->id);

to Yii::app()->user->setId($this->[color="#FF0000"]users/color->id);

Hope this helps.

Oh wow, thanks Sonny, that is. Such a silly mistake I made, :(

Again, thanks a lot for your help.

Tri

I had this problem as well. Everything, syntax wise, looked fine - My solution was to remove the database schema prefixes found in the model which I had added when creating models via Gii.