开发者

CakePHP view action

开发者 https://www.devze.com 2023-02-16 22:48 出处:网络
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.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号