benhowdle89
benhowdle89

Reputation: 37464

CakePHP view action

Go easy, I'm just starting to learn CakePHP.

I'm having to ask this question because i dont really feel Cake has the greatest documentation.

I have the simplest of code:

function view($id = NULL){
    $this->Post->id = $id;
    $this->set('post',$this->Post->read());
}

What i'm asking is what exactly is $this->Post->id = $id; doing? I understand what is being assigned but i'm a little unclear of what it's being assigned to.

Thanks

Upvotes: 0

Views: 635

Answers (1)

Andrea
Andrea

Reputation: 20493

The controller holds an instance of the corresponding model. So $this->Post is the instance of the model, which is accessible from the controller. This is an istance of the model Post, which inherits from AppModel, which in turn inherits from Model. As such it has a public property id, inherited from Model, and you get this property by $this->Post->id.

The object relational mapping of CakePHP assures you that when you call the method $this->Post->read(), you will retrieve the data stored in the table associated to the model Post, in the column identified by the id $id.

Upvotes: 4

Related Questions