Welcome Guest, Not a member yet? Register   Sign In
I need help
#1

[eluser]rudejason[/eluser]
I have only started using Codeigniter and i love it!
I have found that in my controllers i am using the same functions over and over. So i thought build a custom library and then i can use that.
here is my code

Code:
class Mygeodata
{    
    var $CI;
    function Mygeodata()
    {
        $CI =& get_instance();
        $CI->load->database();
    }
    
    function get_countries()
    {
        $query = $this->CI->query('SELECT `con_id`,`name` FROM `vb_geo_countries` ORDER BY `name`');
        foreach($query->result() as $row)
        {
            $country_list .= '<option value="' . $row->con_id . '">' . $row->name . '</option>';
        }
        return $country_list;
    }

when i run this it gives me this error...
Call to a member function query() on a non-object
what am i doing wrong?

Thank you in advance!
#2

[eluser]Atharva[/eluser]
It will be
Code:
$this->CI->db->query
#3

[eluser]rudejason[/eluser]
Thanks but still no go

i have tried
Code:
$this->CI->db->query()
no luck

Code:
$CI->db->query()
The above gives this error
Severity: Notice
Message: Undefined variable: CI
Filename: libraries/Mygeodata.php
Line Number: 15
#4

[eluser]Atharva[/eluser]
Try
Code:
$this->CI =& get_instance();

in constructor. I missed it earlier.
#5

[eluser]rudejason[/eluser]
That was it,
Thank you so much! Gonna save me a lot of time retyping all the functions for each controller!!!!!

Thanks Again!




Theme © iAndrew 2016 - Forum software by © MyBB