I am making first website using codeigniter framework. I have made a user class with a method to check if a user is logged in like :
public function is_logged_in()
{
$this->load->library('session');
$loggedin = $this->session->userdata('logged_in');
if ($loggedin)
{
return TRUE;
}
else
{
return FALSE;
}
}
Now i have a menu in my header with a button which needs to change depending on the login status. If the user is not logged in i want to show a login button, else a logout button (with the right links of course). I think in MVC there should be only html and only php where needed. Where should i place the check to see if i show the login or logout button, should i do it in every controller where i call the header like:
$data['menubutton']= $this->getbutton();//something to get the button
$this->load->view('templates/header', $data);
If i would do it that way i need to add it to every controller, should i just do the check in the view, or is there another simple solution.
Question in short what is the best way/position to create the correct menu button depending on login status? (login or logout button)