关于php:cakephp中$this->的含义

Meaning of $this-> in CakePHP

本问题已经有最佳答案,请猛点这里访问。

Possible Duplicate:
PHP: self vs. $this

在cakephp中,$this->是什么意思?

请分两部分回答…$this指的是什么?->指的是什么?

有人能用post控制器中的语句$this->post->find("all")清楚地解释每个部分吗?如果在posts控制器中,为什么需要->post部分?


$这是指您要使用的类。例如,如果您看到$this->post->find("all"),您将尝试访问扩展appmodel的类post。通过约定,post模型使用数据库中的posts表。$this->post->find("all")的使用是因为appmodel有find()方法,post模型扩展了appmodel。

http://api.cakephp.org/class/app-model网站http://book.cakephp.org/view/22/cakephp-conventions


它是对当前对象的对象引用。


在潜入cakephp之前,您一定要阅读关于类的php文档。

根据官方参考:

Every class definition begins with the
keyword class, followed by a class
name, which can be any name that isn't
a reserved word in PHP. Followed by a
pair of curly braces, which contains
the definition of the classes members
and methods. A pseudo-variable, $this
is available when a method is called
from within an object context. $this
is a reference to the calling object
(usually the object to which the
method belongs, but can be another
object, if the method is called
statically from the context of a
secondary object).

不是最简单的定义,但这确实是在cakephp中导航代码需要知道的东西。