Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] library question so simple/noob you'll be proud to answer me ...
#1

[eluser]Dagobert Renouf[/eluser]
Hi guys,

My library :

Code:
public function __construct()
    {

        $CI =& get_instance();
        $CI->load->helper('url');
        $CI->load->database();

    }

    public function display($table, $params = "")
    {
        if ($this->db->table_exists($table))
        {

            echo 'a';

        }

    }

it says db is not defined, why is that ? (I load the database in the constructor)
#2

[eluser]Seppo[/eluser]
CI does not attach the db object to all libraries... you should use
Code:
$CI =& get_instance();
        if ($CI->db->table_exists($table))
#3

[eluser]ontguy[/eluser]
I think it should setup like this:

Code:
var $CI;

public function __construct()
    {

        $this->CI =& get_instance();
        $this->CI->load->helper('url');
        $this->CI->load->database();

    }

    public function display($table, $params = "")
    {
        if ($this->CI->db->table_exists($table))
        {

            echo 'a';

        }

    }
#4

[eluser]Dagobert Renouf[/eluser]
ahah I thought it would be simpler than that :

Seppo : same error

ontguy : "Call to a member function table_exists() on a non-object"
#5

[eluser]ontguy[/eluser]
What version of php are you working with?
#6

[eluser]Dagobert Renouf[/eluser]
PHP Version 5.2.6
#7

[eluser]ontguy[/eluser]
Does anything from the url helper work in that function? try
Code:
echo base_url();

If it works, the CI reference was passed successfully to the library.
#8

[eluser]Dagobert Renouf[/eluser]
yes it does work
#9

[eluser]xwero[/eluser]
Try loading the database in the method
#10

[eluser]Dagobert Renouf[/eluser]
still the same :-s

Call to a member function database() on a non-object




Theme © iAndrew 2016 - Forum software by © MyBB