CodeIgniter Forums
[SOLVED] library question so simple/noob you'll be proud to answer me ... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED] library question so simple/noob you'll be proud to answer me ... (/showthread.php?tid=9528)

Pages: 1 2


[SOLVED] library question so simple/noob you'll be proud to answer me ... - El Forum - 06-28-2008

[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)


[SOLVED] library question so simple/noob you'll be proud to answer me ... - El Forum - 06-28-2008

[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))



[SOLVED] library question so simple/noob you'll be proud to answer me ... - El Forum - 06-28-2008

[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';

        }

    }



[SOLVED] library question so simple/noob you'll be proud to answer me ... - El Forum - 06-28-2008

[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"


[SOLVED] library question so simple/noob you'll be proud to answer me ... - El Forum - 06-28-2008

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


[SOLVED] library question so simple/noob you'll be proud to answer me ... - El Forum - 06-28-2008

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


[SOLVED] library question so simple/noob you'll be proud to answer me ... - El Forum - 06-28-2008

[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.


[SOLVED] library question so simple/noob you'll be proud to answer me ... - El Forum - 06-28-2008

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


[SOLVED] library question so simple/noob you'll be proud to answer me ... - El Forum - 06-28-2008

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


[SOLVED] library question so simple/noob you'll be proud to answer me ... - El Forum - 06-29-2008

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

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