Welcome Guest, Not a member yet? Register   Sign In
Sessions/Simple Login - Accessing logged_in status from a view
#1

[eluser]autoreverse[/eluser]
I'm building a site with a common view template which includes a Login/Logout menu option that should toggle with the visitor's logged-in status.

I'm using SimpleLogin to control access. My questions is: How can I access changed session user_data from a view (without redirecting)?

SimpleLogin calls sess_destroy on logout which only sets a new cookie so does not affect the session data object.

I've tried placing
Code:
$this->session->set_userdata('logged_in', FALSE);
in the controller but I can't figure out how to reflect this in the view.

The relevant controller code is:
Code:
function logout() {

    //Logout
    $this->simplelogin->logout(); // call sess_destroy() in the CI Session class.

    $this->data['page_content'] = 'account_loggedout'; // identifies the 'logged_out' view
    $this->data['main_title'] = 'Logged Out'; // page title

    $this->load->view('templates/container', $this->data); // load the generic template
    
}



The view template:
Code:
<?php if($this->session->userdata('logged_in')) { ?>

    <a href="/user/logout">Logout</a>

&lt;?php } else { ?&gt;

    <a href="/user/">Client Login</a>

&lt;?php } ?&gt;

Any help would be appreciated.
#2

[eluser]autoreverse[/eluser]
I've come up with the following code in my view:
Code:
&lt;?php // Toggle login/logout menu option

    $CI =& get_instance();
    if($CI->session->userdata('logged_in')) {
        echo '<a href="/account/logout">Logout</a>';
    } else {
        echo '<a href="/account/">Client Login</a>';
    }

?&gt;
It works but I don't think it's ideal from a puristic point of view. Any comments from MVC or CodeIgniter gurus appreciated!



P.S. Mods please move this topic to the Code and Application Development forum if more suitable there.




Theme © iAndrew 2016 - Forum software by © MyBB