Welcome Guest, Not a member yet? Register   Sign In
How to use variables from class globally in views
#1

[eluser]mabright[/eluser]
I am working on a new site and I am new to CI. I have a controller called messages that contains a variable called $inbox_count that contains the number of inbox messages in the database for the logged in user.

I can retrieve the variable fine in my messages view which is called from my messages controller but when I try to use the variable in my user navigation menu to display to the user if there are new messages (i.e. if the user is on another page other than the message center, the navigation bar would display the number of messages next to the inbox link.

I.e. Navigation menu bar: Home | Account | (2) Inbox | Order Overview |
---------------------------------------------

I tried calling $this->messages->inbox_count and $this->messages->get_inbox_count() from within my template page that contains the navigation menu code but I get the below error.

Fatal error: Call to a member function get_inbox_count() on a non-object in....


Code:
<?php
class Messages extends Controller {
    
    var $inbox_count = 0;
    var $sent_count  = 0;
    var $trash_count = 0;
    
    public function __construct()
    {
        parent::Controller();
        
        $this->load->model('member/Messages_model');
        
        $this->load->library('input');                
        $this->load->library('form_validation');        
        $this->form_validation->set_error_delimiters('<span class="input_error">', '</span>');
        
        $this->inbox_count = $this->Messages_model->get_folder_count('INBOX');
        $this->sent_count = $this->Messages_model->get_folder_count('SENT');
        $this->sent_count = $this->Messages_model->get_folder_count('TRASH');
    }

    public function index()
    {
        if($this->session->userdata('logged_in') != TRUE)
      {
          redirect('member/login');
      }      
        $this->_display();
    }

    public function inbox()
    {
        $this->inbox_count = $this->Messages_model->get_folder_count('INBOX');
        $this->_display();
    }
    ................


Messages In This Thread
How to use variables from class globally in views - by El Forum - 01-10-2010, 09:02 PM
How to use variables from class globally in views - by El Forum - 01-10-2010, 09:15 PM
How to use variables from class globally in views - by El Forum - 01-10-2010, 09:24 PM
How to use variables from class globally in views - by El Forum - 01-11-2010, 01:38 AM
How to use variables from class globally in views - by El Forum - 01-11-2010, 11:10 AM
How to use variables from class globally in views - by El Forum - 01-11-2010, 05:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB