Cannot Understand following code

hi folks

I am new to Php as well as Yii and you can say that i am a new pilot and yet I am learning flying at A380 :P

issue is that everything is working fine for me until CHAPTER 6

I cannot understand concept of Returning back to the owner and requester dropdowns

I am implementing it side by side and in my case Issue.php did not generated relations ,I just then placed following code


public function relations()

  {

    // NOTE: you may need to adjust the relation name and the related

    // class name for the relations automatically generated below.

    return array(

      'owner' => array(self::BELONGS_TO, 'User', 'owner_id'),

      'project' => array(self::BELONGS_TO, 'Project', 'project_id'),

      'requester' => array(self::BELONGS_TO, 'User', 'requester_id'),

    );

  }

I want some description in other text as i donot understand that is written in book .

plus why self:: used?

also this one is a bit more tricky


public function relations()

    {

        // NOTE: you may need to adjust the relation name and the 

related

        // class name for the relations automatically generated below.

        return array(

            'issues' => array(self::HAS_MANY, 'Issue', 'project_id'),

            'users' => array(self::MANY_MANY, 'User', 'tbl_project_

user_assignment(project_id, user_id)'),

        );

    }

thanks in advance

You may want to go back and read the section about "Building the Database and Relationships" on pp 96-97.

It sounds like you did not build the Foreign Keys in your database. This can occur if you are straight copying the code from the book, into your MySQL SQL window because the copy/paste turns back ticks (`) in to single quotes (’).

You should definitely make sure that gii is generating the relations for you in the model before you attempt to go further.

The key point of this exercise is to learn how to create an execution context within which an Issue can be created, and thus how to populate the owner and requestor fields of the Issue Record.

The majority of the first part of the chapter was discussing how to create such a context so that the issue can be constrained to only one project. In order for this to happen the issue has to know which project it belongs to. This took us on a bit of a side track.

In the section labeled "Returning back to the owner and requester dropdowns" the author is getting back to the original problem which can now be solved thanks the the knowledge we have gained in the first part of the chapter about how to set up a context for each issue.

self is used to reference the class itself , that is the abstract form of the class as opposed to a concrete instance of a class ( where you would use $this)

Hope this helps.