Reputation: 569
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 */
Upvotes: 2
Views: 9452
Reputation: 227220
That's not how you call a function from a helper. Helper functions aren't part of the CodeIgniter object. They're just functions.
$string = connect($url);
Upvotes: 1
Reputation: 11552
CodeIgniter helpers should be functions, not classes.
Try simply:
$string = connect($url);
Upvotes: 5