[eluser]Madigan[/eluser]
Hey, I'm trying to learn codeigniter and make a simple blog. In order to have pages that react to different types of users (not logged in, logged in, admin, etc.), I am extending the base controller so that it has a little "logged in" variable. However, when I extend my controller, I get an error saying that the variable doesn't exist when I try to extend the class.
Code:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed.');
class MY_Controller extends CI_Controller
{
public $loggedIn = "";
function __construct()
{
parent::__construct();
//$loggedIn = $this->session->userdata('privileges');
$loggedIn = "test";
}
}
?>
Code:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class CHome extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('vhome', array('loggedIn' => $loggedIn));
}
}
?>
Code:
<!DOCTYPE html>
<html>
<head>
<title>My Site</title>[removed]
</head>
<body>
<header id="header"></header>
<nav id="navBar"></nav>
<section id="content"><? echo $loggedIn; ?></section>
<footer id="footer"></footer>
</body>
</html>
I think I should be able to access any public/protected variables from the parent class. However, for some reason it doesn't seem to be working. Any ideas?