复制 Codeigniters 加载函数
我最近一直在玩 Codeigniter,看看能从中学到什么。我遇到了加载函数,想知道是否有人知道它是如何完成的。基本上,它看起来像这样:
$this->load->model('Model_name');
$this->Model_name->some_function();
现在 load 显然是一个类,并且创建了一个实例并调用 load。加载包含类“Model_name”并创建它的实例。但我无法解决的部分是,加载类如何创建一个名为“Model_name”的“类变量”以在代码的第二行中使用?我实际上将如何在 php.ini 中实现它?
谢谢。
I have recently been playing around with Codeigniter to see what I can learn from it. I came across the load function and was wondering if anyone knows how its done. Basically, it looks something like:
$this->load->model('Model_name');
$this->Model_name->some_function();
Now load is obviously a class and an instance is created and called load. And load includes the class "Model_name" and creates an instance of it. But the part I cant work out, is how does the load class create a "class variable" named "Model_name" to be used as in the second line of the code? And how would I actually go about implementing this in php.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该类的基本作用是记住所有创建的对象(例如 $this),然后通过引用将新创建的类分配为这些类中的变量。
然而,它在后台做的事情远不止这些。您知道您可以打开“loader.php”然后阅读它的作用,对吧?
What the class basicly does is remembering all the created objects ($this for instance) and then assign the newly created class by reference as a variable in those classes.
however, it does a lot more stuff in the background than that. You know you can just open 'loader.php' and then read what it does, right?
这种事情适用于像 PHP 这样的解释语言。尽管想象这一点可能会非常令人困惑,特别是如果您有使用 C++、C# 等严格语言的经验。
其想法是,有一些 PHP 函数可以执行 PHP 代码,并且结果将在脚本的其他位置可见。
This kind of things work with interpreted languages like PHP. Though it can be very confusing to picture this, specially if you are experienced with strict languages such as C++, C# etc.
The idea is, there are PHP functions that can execute PHP code and the result will be visible elsewhere in the script.