$ this关键字在CodeIgniter的视图 [英] $this keyword in view in CodeIgniter
问题描述
我想了解CodeIgniter中视图文件中的 $ this-> load-> view()
如何工作 。
核心/ Controller.php正在调用core / Loader.php,然后调用_ci_load(),然后调用 include path / to / view');
不应 $ this
那个时候的Loader类呢?如何 $ this
指向控制器?
根据我的理解,你应该调用$ this-> view()在视图文件中。不是$ this-> load-> view(),因为load()函数在Loader内部是不可访问的。它是Controller基类的类变量。即 $ this-> load =& load_class('Loader');
请注意:我试图理解CodeIgniter内部。我完全知道如何嵌入视图文件在其他视图文件作为CodeIgniter用户。请不要离开解释如何使用 $ this-> load()的答案。
上次我检查, $ this
c $ c> CI_Loader ,请在视图中尝试 var_dump($ this);
< hr>
查看:
https://github.com/EllisLab/CodeIgniter/blob/develop/system/core/Controller.php
is_loaded();
返回一个数组,其中已经加载了来自主容器的类名和别名。
$ this-> load
是控制器内 CI_Loader
的实例。 p>
检查:
https://github.com/EllisLab/CodeIgniter/blob/develop/system/core/Loader.php
第778行
I'm trying to understand how $this->load->view()
works inside of a view file in CodeIgniter.
The core/Controller.php is calling core/Loader.php which then calls _ci_load() which in turn does an include('/path/to/view');
Shouldn't $this
refer to the Loader class at that point? How is $this
referring to the controller?
By my understanding, you should have to call $this->view() inside of a view file. Not $this->load->view() because the load() function is not accessible inside of the Loader. It's a class variable of the Controller base class. i.e, $this->load =& load_class('Loader');
Please note: I'm trying to understand the CodeIgniter internals. I know perfectly well how to embed view files in other view files as a CodeIgniter user. Please do not leave answers explaining how to use $this->load().
Last time I checked, $this
was of class CI_Loader
, try var_dump($this);
inside a view.
Check out:
https://github.com/EllisLab/CodeIgniter/blob/develop/system/core/Controller.php
is_loaded();
returns an array with the already loaded classnames and their aliases from the main container.
$this->load
is then an instance of CI_Loader
inside the controller.
Check:
https://github.com/EllisLab/CodeIgniter/blob/develop/system/core/Loader.php
Line 778
这篇关于$ this关键字在CodeIgniter的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!