Jump to content

Archived

This topic is now archived and is closed to further replies.

c_pattle

Codeigniter session problem

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

Share this post


Link to post
Share on other sites
However it's not possible to load the session library from within another library.

 

Sure it is.

$CI =& get_instance();

$CI->load->library('session');

 

Alternatively you can autoload the session library in the application/config/autoload.php file.

Share this post


Link to post
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?

Share this post


Link to post
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();

Share this post


Link to post
Share on other sites

Thanks

 

I have tried both of those but I still get the same error.  Do you think its something to do with how I have codeigniter set up?

Share this post


Link to post
Share on other sites

×
×
  • 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.