$this 在 cake php 中的视图文件上下文中意味着什么

What does $this mean in the context of view files in cake php

在cakePHP的.ctp文件中使用$this时,$this指的是什么? 首先,我认为它应该是调用该特定视图的控制器对象。但在一些教程中,$this->html 被用在许多 .ctp 文件中。但是我在控制器 class 中找不到名为 html 的 属性。因此 $this 不能引用控制器 class。那它到底指的是什么呢?

请注意,我是 cakePHP 的初学者。

Please note that I am a beginner in cakePHP.

这听起来更像是您 php 的初学者。 Have a read about OOP in php.

如果您不确定对象是什么,只需调试它:

debug(get_class($this));

And see what it will show. And the helpers like the HtmlHelper are accessed through magic __get().

我建议您阅读框架的源代码及其文档,这样您可以比通过教程学到更多,因为您可以更深入地了解框架,并且可以在 php.

But in some tutorials

什么教程?我会说 stick to the official documentation for the first steps。野外教程并不总是你能得到的最好的。官方书籍非常详细地解释了 MVC 在 CakePHP 中的工作方式。