Jump to content

Codeigniter session problem


c_pattle

Recommended Posts

I have a library called "Layout" which controls the main layout for my site.  In my header method I have this code that checks to see if the "loggedin" variable is set and then loads a view depending on the outcome. 

 

$loggedin = 0;
        if($loggedin)
        {
            $aData['myAccount'] = '<div class="my_account">';
            $aData['myAccount'] .= $this->load->view('account/myaccount', '', true);
            $aData['myAccount'] .= '</div>';
        }
        else
        {
            $aData['myAccount'] = '<div class="login_or_register">';
            //Assign the login view to the $aData array for display
            $aData['myAccount'] .= $this->load->view('account/login', '', true);
            $aData['myAccount'] .= '</div>';
        }

 

This works but what I want to do is to check if a session variable is set.  However it's not possible to load the session library from within another library.  Is there a way round this problem?

 

Thanks

Link to comment
Share on other sites

Thanks.  I have autoloaded the session and I have the following code

 

$this->ci =& get_instance();
$this->ci->load->library('session');

 

but I still get the error

 

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

 

Is there something I'm doing wrong?

Link to comment
Share on other sites

You then need to use it via $this->ci->session instead of $this->session

 

EDIT: Wait, so you autoloaded the session?

 

In that case, while in another library you need to take the same steps but you don't need to load it. So in another library:

$CI =& get_instance();

$CI->session->userdata();

Link to comment
Share on other sites

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.