问题描述
愚蠢的问题,我知道,
在所有教程中,他们都没有解释为什么使用 $this.
From all the tutorials they do not explain why they use $this.
$this 是否类似于 Codeigniter 中基类的对象?
Is $this like an object from a base class in Codeigniter?
欢迎任何解释!:)
谢谢
推荐答案
为了实际回答你的问题,$this
实际上代表了单例 Codeigniter 实例(实际上是控制器对象).
To actually answer your question, $this
actually represents the singleton Codeigniter instance (which is actually the controller object).
例如,当您加载库/模型时,您将它们附加到此实例,以便您可以将它们作为此实例的属性进行引用.
For example when you load libraries/models, you're attaching them to this instance so you can reference them as a property of this instance.
在 codeigniter 中获取此实例的另一种方法是您在构建可移植库时使用的 get_instance()
函数.
Another way to get this instance in codeigniter is the get_instance()
function that you use when building portable libraries.
这篇关于$this 实际上是什么意思>代码点火器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!