Welcome Guest, Not a member yet? Register   Sign In
Custom controller won't inherit variables
#1

[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>
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;My Site&lt;/title&gt;[removed]
&lt;/head&gt;
&lt;body&gt;
  &lt;header id="header"&gt;&lt;/header>
  <nav id="navBar"></nav>
  <section id="content">&lt;? echo $loggedIn; ?&gt;</section>
  <footer id="footer"></footer>
&lt;/body&gt;
&lt;/html&gt;
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?


Messages In This Thread
Custom controller won't inherit variables - by El Forum - 09-03-2012, 03:06 PM
Custom controller won't inherit variables - by El Forum - 09-03-2012, 05:03 PM
Custom controller won't inherit variables - by El Forum - 09-03-2012, 06:24 PM
Custom controller won't inherit variables - by El Forum - 09-04-2012, 07:52 AM
Custom controller won't inherit variables - by El Forum - 09-04-2012, 09:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB