[eluser]Sven Delle[/eluser]
This is driving me totally nuts!
I STILL seem to have a huge problem understanding controllers and how to point the user to the right place.
Scenario:
I have an (so far) empty admin.php controller which extends an Admin_Controller.
The Admin_Controller - which look like this - checks if a user is logged in:
Code:
<?php
class Admin_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
if(!$this->session->userdata('logged_in'))
{
$this->go_login();
}
}
private function go_login()
{
redirect('admin/admin_login');
}
}
/* End of file: ./application/modules/admin/controllers/admin.php */
This all works perfectly!
Well, that is - until next time you try to login (another browser window for some reason).
Then I simply CANNOT just redirect the already logged in user to the admin panel!
If I simply add an else statement like this:
Code:
if(!$this->session->userdata('logged_in'))
{
$this->go_login();
}
else
{
redirect('admin', 'location');
}
The browser cannot 'redirect properly' it complains. Now, I know I'M the stupid one and somehow make myself end up in an endless loop. But I simply cannot get my head around this issue.
Could someone explain to me WHAT it is that I DONT'T GET?
NOTE: The reason for the Admin_Controller is that I plan on having a lot of other admin controllers in the end, and this is an easy way to protect them all.