【问题标题】:Calling a library from inside a helpers function in Codeigniter从 Codeigniter 中的辅助函数内部调用库
【发布时间】:2010-11-24 05:01:02
【问题描述】:

我可以从帮助程序中加载库吗?

$this->load->library('name');

谢谢, 最大

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:
    function sendEmail() {
         $CI =& get_instance();
         $CI->load->library('email'); // load library 
    }
    

    【讨论】:

      【解决方案2】:
      // ------------------------------------------------------------------------
      /**
       * URL String
       *
       * Returns the URI segments.
       *
       * @access  public
       * @return  string
       */
      if ( ! function_exists('uri_string'))
      {
          function uri_string()
          {
              $CI =& get_instance();
              return $CI->uri->uri_string();
          }
      }
      

      是的,当然。

      我不同意 jimyi 的回答。 CI 自己的 url helper 加载 URI 类。

      【讨论】:

      • 其次,如果您创建了一个自定义库,您可能希望为其添加帮助程序。
      【解决方案3】:

      没有。助手的目的是“执行一项特定的任务,而不依赖于其他功能。”

      引用自 CI 的 helpers page

      如果您需要在帮助程序中包含库,请考虑将其改为库。

      【讨论】:

      • 我不同意这一点。 CI 自己的 url helper 加载 URI 类。
      • 你当然可以加载一个库。这是可能的,我已经使用了这种能力。 jimyi的话100%是假的。
      • 可以从辅助函数内部加载库 - 检查stackoverflow.com/a/6327423/636762
      猜你喜欢
      • 2021-10-12
      • 2014-01-23
      • 1970-01-01
      • 2015-11-09
      • 2012-01-07
      • 2011-08-24
      • 2015-05-08
      • 2019-11-25
      • 1970-01-01
      相关资源
      最近更新 更多