OOP Question!

#1
[eluser]Lazos[/eluser]
Hi. I have this Home Controller and using Admin_Theme::doTopMenu($topmenu) I run a function that is in a custom Admin_Theme class. In the user guide is writing that if you want to call a function of a library use this $this->admin_theme->doTopMenu();. If I write it this way I am getting the following error Message: Undefined property: Admin_Theme::$lang in my Admin_Theme class. Now if I change the way the function is called like this Admin_Theme::doTopMenu($topmenu); everything is working properly.

If is not big trouble can you explain me what is the difference between them and why when I use this -> is not working but when I use this :: it is? Also which way do you recommend?
Thanks.

EDIT1:
Well I found a solution in another post in the forum. I had to use this $this->CI =& get_instance(); inside my _constructor. I am not sure if is correct though. If is correct or not still try to explain it.

Code:
class Home extends Controller {
    
    function index()
    {    
        $user_ip = $this->input->ip_address();
        $userdata = $this->my_session->sess_read($user_ip, ADMIN_HOME);
        if ($userdata['session_logged_in'] != 1) {
            _redirect('index.php/admin/login');
        }
        $this->load->model('admin/home_model', 'home_model');
        $siteprefs = $this->home_model->site_preferences();
        $topmenu = $this->home_model->extract_top_menu();
        $this->load->library('admin_theme');
        $this->admin_theme->_constructor($userdata['user_id']);
        $topmenu = Admin_Theme::doTopMenu($topmenu);
        $headers = Admin_Theme::sendHeaders();
        $templatevars = array (
            'T_MENU'                    => $topmenu,
            'L_WELCOME_USER'             => $this->lang->line('welcome'),        
            'L_ADMIN_PANEL_TITLE'        => $this->lang->line('admin_panel_title'),
            'V_ADMIN_PANEL_TITLE'         => $siteprefs['sitename'],
            'V_FIRST_LAST_NAME'             => $userdata['first_name']." ".$userdata['last_name']
            );

        $this->parser->parse('admin/header.tpl', $templatevars);
    }
}

Code:
function doTopMenu ($topmenu) {
        $final = array();                                                          
                                                                            
        foreach ($topmenu as $value)
        {
            $description = array('description' => $this->lang->line($value['title']));
            $title = array ('title' => $value['title']);
            $parent = array ('parent' => $value['parent']);
            $url = array ('url' => $value['url']);
            $target = array ('taget' => $value['target']);
            $showinmenu = array ('show_in_menu' => $this->admin_theme->lazos($value['show_in_menu']));
            $row = $title + $parent + $url + $target + $showinmenu + $description;
            array_push($final, $row);
            
        }
    }


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.