Codeigniter – How to load a helper within a library in codeigniter

codeigniterhelper

I created a library for API access, and I created a seperate helper for common functions used by the library. In codeigniter, new libraries can access native classes by creating an instance of themselves using…

$example_instance = & get_instance();

I did this, loaded my helper- but every time the helper function is called i get the "trying to access a non-object" error. What am I doing wrong?

Here's what I have

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class api_example {
private $api;
public function __construct(){
    $this->api = & get_instance();
    $this->api->load->helper('helper_test');
}   

public function search_recent($param){

    $string = $this->api->helper_test->connect($url); //error!!!

    return $xml;
}


}

/* End of file  */

Best Answer

CodeIgniter helpers should be functions, not classes.

Try simply:

$string = connect($url);
Related Topic