c_pattle Posted December 8, 2011 Share Posted December 8, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/252734-codeigniter-session-problem/ Share on other sites More sharing options...
scootstah Posted December 8, 2011 Share Posted December 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252734-codeigniter-session-problem/#findComment-1295661 Share on other sites More sharing options...
jotorres1 Posted December 8, 2011 Share Posted December 8, 2011 I would suggest to just autoload it in the autoload config file. Quote Link to comment https://forums.phpfreaks.com/topic/252734-codeigniter-session-problem/#findComment-1295666 Share on other sites More sharing options...
c_pattle Posted December 8, 2011 Author Share Posted December 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252734-codeigniter-session-problem/#findComment-1295669 Share on other sites More sharing options...
scootstah Posted December 8, 2011 Share Posted December 8, 2011 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(); Quote Link to comment https://forums.phpfreaks.com/topic/252734-codeigniter-session-problem/#findComment-1295673 Share on other sites More sharing options...
c_pattle Posted December 8, 2011 Author Share Posted December 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252734-codeigniter-session-problem/#findComment-1295681 Share on other sites More sharing options...
scootstah Posted December 8, 2011 Share Posted December 8, 2011 I don't know - how do you have codeigniter set up? Quote Link to comment https://forums.phpfreaks.com/topic/252734-codeigniter-session-problem/#findComment-1295699 Share on other sites More sharing options...
ME_php Fresher Posted February 21, 2012 Share Posted February 21, 2012 why dont you try loading from helper class. Quote Link to comment https://forums.phpfreaks.com/topic/252734-codeigniter-session-problem/#findComment-1319512 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.