[eluser]NateL[/eluser]
I've got my admin section that I'm trying to work out right now. If I've got all sorts of methods, it makes no sense to add the if/else statement to EVERY method - so instead i've added it to the constructor, like so:
Code:
class Welcome extends Controller
{
function __construct()
{
parent::__construct();
$this->load->library('tank_auth');
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
}
}
function index()
{
$this->load->view('welcome', $data);
}
}
However, this doesn't work. How come my $data variable isn't available to index? I want the user_id and username to be available to all of my methods, but it goes against the DRY concept if I have to put that $data info in every method.