代码点火器从库内加载库?

发布于 2024-10-04 21:03:19 字数 206 浏览 6 评论 0原文

是否可以从代码点火器中的库中加载库?

执行

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把回忆走一遍 2024-10-11 21:03:19

检查您引用的library() 方法的CI_Loader 类的签名:

/**
 * Class Loader
 *
 * This function lets users load and instantiate classes.
 * It is designed to be called from a user's app controllers.
 *
 * @access  public
 * @param   string  the name of the class
 * @param   mixed   the optional parameters
 * @param   string  an optional object name
 * @return  void
 */
function library($library = '', $params = NULL, $object_name = NULL)
{

它返回void,所以当然无论您将返回值设置为什么,都将为null。我认为您对该方法的目的感到困惑。它加载库并将其附加到 codeigniter 超级对象,以便您可以将其引用为:

$this->CI->[library name]

在您的情况下,您只想引用新加载的库(我猜测是基于一些特定的验证器库)在你的代码片段上)以通常的方式:

$this->CI->[newly loaded super awesome validator library]

Check out the CI_Loader class's signature for the library() method you refer to:

/**
 * Class Loader
 *
 * This function lets users load and instantiate classes.
 * It is designed to be called from a user's app controllers.
 *
 * @access  public
 * @param   string  the name of the class
 * @param   mixed   the optional parameters
 * @param   string  an optional object name
 * @return  void
 */
function library($library = '', $params = NULL, $object_name = NULL)
{

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:

$this->CI->[library name]

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:

$this->CI->[newly loaded super awesome validator library]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文