[eluser]x_dde_x[/eluser]
Hey Codeigniter helpers,
I'm in the process of converting all of my old sites to codeigniter (figure it's good practice and a great education on codeigniter), and I'm wondering if I'm going about this the right way.
Here's the issue: I have a custom Library that a lot of my controllers will use to render passed xml strings into dynamic charts. There are a few database calls that the library uses to load dates that appear in the table. However, I cannot get the functions to use CI's database functions unless I instantiate the CI instance and database from each and every function.
Here's the code, maybe you can quickly tell where I've gone wrong (or if I need to create a custom Model to pull database calls, and separate that from the Library).
Code:
class Chart {
var $CI;
function Chart()
{
$CI =& get_instance();
$CI->load->database();
$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');
}
function render_date_range($interval,$timeframe)
{
$sql=$CI->db->query("text of query");
}
trying to call the render date function will fail with: Undefined variable: CI unless I add $CI =& get_instance(); and $CI->load->database(); from each and every function...