Welcome Guest, Not a member yet? Register   Sign In
Constructor Problem
#1

[eluser]marty123[/eluser]
Hi, I'm trying to implement my own library, there is an constructor like this one:
Code:
class Menu {
    
    function Menu()
    {
        $CI =& get_instance();  


    }

fucntion get_menu ($param){

$CI ->load->model('m_menu');
};
function three(){
...
}

But when I try to use $CI in functions, there is an error :


A PHP Error was encountered

Severity: Notice

Message: Undefined variable: CI

Filename: libraries/menu.php

Line Number: 29

I call my library this way:
Code:
$this->load->library('menu');
$menu1 = new Menu();
$error['menu'] = $menu1->get_menu('PL');
the solution is to add $CI =& get_instance();
in all functions in the class, but I thought it should take $CI from constructor, am I wrong?


Messages In This Thread
Constructor Problem - by El Forum - 06-21-2009, 03:48 AM
Constructor Problem - by El Forum - 06-21-2009, 03:52 AM
Constructor Problem - by El Forum - 06-21-2009, 04:14 AM
Constructor Problem - by El Forum - 06-21-2009, 04:18 AM
Constructor Problem - by El Forum - 06-22-2009, 06:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB