This may be a basic Codeigniter (or php) question, but I'm trying to check if a user is logged in with Ion Auth for every page call so I can provide a 'Sign-in' or 'Sign-out' link.
I have my header, content, and footer views loading from MY_Loader class and was trying to use $this->ion_auth->logged_in()
to check if a user is logged in, but I get this php error,
PHP Error: Undefined property: MY_Loader::$ion_auth
Here is MY_Loader.php:
<?php
/**
* /application/core/MY_Loader.php
*
*/
class MY_Loader extends CI_Loader {
public function template_main($template_name, $vars = array(), $return = FALSE)
{
$vars['signin'] = $this->ion_auth->logged_in() ? 'signout' : 'signin';
$vars['signin_text'] = $this->ion_auth->logged_in() ? 'Sign-out' : 'Sign-in';
$content = $this->view('frontend/main_template/header', $vars, $return);
$content .= $this->view($template_name, $vars, $return);
$content .= $this->view('frontend/main_template/footer', $vars, $return);
if ($return)
{
return $content;
}
}
}
/* End of MY_Loader.php */
/* Location: ./application/core/MY_Loader.php */
I am autoloading the ion_auth library. How can I call the logged-in() function in MY_Loader class?
The autoloaded files probably haven't been loaded yet. Add $this->load->library('ion_auth') to the top of the method.