代码点火器从库内加载库?
是否可以从代码点火器中的库中加载库?
执行
$this->validator = $this->CI->load->library('validators/'.$params['validator']);
如果我从另一个库中 $this->验证器为NULL。
为什么会这样呢?
Is it possible to load an library from within a library in code igniter?
If I do
$this->validator = $this->CI->load->library('validators/'.$params['validator']);
from within another library $this->validator is NULL.
Why would this be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查您引用的library() 方法的CI_Loader 类的签名:
它返回void,所以当然无论您将返回值设置为什么,都将为null。我认为您对该方法的目的感到困惑。它加载库并将其附加到 codeigniter 超级对象,以便您可以将其引用为:
在您的情况下,您只想引用新加载的库(我猜测是基于一些特定的验证器库)在你的代码片段上)以通常的方式:
Check out the CI_Loader class's signature for the library() method you refer to:
It returns void, so of course whatever you set the return value to will be null. I think you're confused about the purpose of that method. Its to load the library and attach it to the codeigniter super-object, so that you can reference it as:
In your case, you'll just want to refer to the newly-loaded library (some specific validator library I'm guessing based on your code snippet) in the usual way: