简体   繁体   中英

Calling a library from inside a helpers function in Codeigniter

Can I load a library from inside a helper?

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

Thanks, Max

function sendEmail() {
     $CI =& get_instance();
     $CI->load->library('email'); // load library 
}
// ------------------------------------------------------------------------
/**
 * 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();
    }
}

Yes, of course.

I disagree with jimyi's answer. CI's own url helper loads the URI class.

No. The purpose of helpers is to "perform one specific task, with no dependence on other functions."

Quoted from CI's helpers page .

If you need to include a library inside of your helper, consider making it a library instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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