简体   繁体   English

找出在 CodeIgniter 中加载助手的位置

[英]Find out where a helper is being loaded in CodeIgniter

I am having a project, that contains several Controllers, Views and Helpers (The original developer, from whom I overtook the job, didn't bother to use Models).我有一个项目,其中包含几个控制器、视图和助手(我接手工作的原始开发人员没有费心使用模型)。 In one of the Controllers (Iframes.php), there is (of course) a function __construct(), an index() and a function called view().在其中一个控制器(Iframes.php)中,(当然)有一个 function __construct()、一个 index() 和一个名为 view() 的 function。 In the construct, there is a $this->load->helper('iframes');在构造中,有一个 $this->load->helper('iframes'); No other helpers are being loaded.没有其他助手正在加载。

The website is being accessed by address https://website.ext/iframes/view/1234567890该网站正在通过地址https://website.ext/iframes/view/1234567890访问

In the iframes_helper.php, there is no reference to another helper file soever.在 iframes_helper.php 中,没有对另一个帮助文件的引用。 But the iframes_helper.php is calling a function called get_loans().但是 iframes_helper.php 正在调用名为 get_loans() 的 function。 That function only exists in one file: loans_helper.php function 只存在于一个文件中:loans_helper.php

There are OTHER Controllers that load the loans_helper.php (by its normal way).还有其他控制器加载了loans_helper.php(以正常方式)。

If I rename the loans_helper.php (to loans_helper.php1), the system won't load, stating a file is missing.如果我将loans_helper.php 重命名为loans_helper.php1,系统将无法加载,说明缺少文件。 It doesn't tell me WHERE there is being referred to the missing file.它没有告诉我在哪里提到了丢失的文件。

I've searched through all the files for我已经搜索了所有文件

load->helper('loans')

even for就算

load->helper('loans

and

('loans')

but there is nowhere a referral to the loans_helper file.但是没有任何地方可以参考loans_helper 文件。 At least not in Controllers that are being used in the Iframes Controller or files belonging to it.至少不在 Iframe Controller 或属于它的文件中使用的控制器中。

But the function get_loans is still accessible.但是 function get_loans 仍然可以访问。 How can this be?怎么会这样? Or rather: how do I find out where the helper is being loaded?或者更确切地说:我如何找出加载助手的位置?

Albert阿尔伯特

Please tell me, if I need to add some code.请告诉我,如果我需要添加一些代码。

You should also search for variants of 'loan' using double quotes, "loan , since that's also valid.您还应该使用双引号"loan loan" 搜索 'loan' 的变体,因为这也是有效的。

At the top of the loans_helper.php file, add debug_print_backtrace(); die;loans_helper.php文件顶部,添加debug_print_backtrace(); die; debug_print_backtrace(); die; , which will output some useful information about the execution path. ,其中会 output 关于执行路径的一些有用信息。 Note that if you're testing in a browser, that you should view the source of the page, to get a more usable format.请注意,如果您在浏览器中进行测试,您应该查看页面的源代码,以获得更可用的格式。 From the backtrace you'll be able to determine how the file is being included (ie via CI's loader system, or directly via include or require ).从回溯中,您将能够确定文件是如何被包含的(即通过 CI 的加载器系统,或直接通过includerequire )。

Here's PHP's documentation on debug_print_backtrace() .这是关于debug_print_backtrace()PHP 文档

Lastly, here are a couple other thoughts on where such a file could be included:最后,这里有一些关于可以包含此类文件的其他想法:

  • Within CI's autoload.php config file.在 CI 的autoload.php配置文件中。 There's an item for autoloading helper files.有一个用于自动加载帮助文件的项目。
  • If Composer exists in the project, check the composer.json file for a reference to the file.如果项目中存在 Composer,请检查 composer.json 文件以获取对该文件的引用。
  • Technically CI's helper files don't need to be included via CI's loader, so the file might be manually included in using include or require .从技术上讲,CI 的帮助文件不需要通过 CI 的加载器包含,因此可以使用includerequire手动包含该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM