[eluser]whitey5759[/eluser]
[quote author="w0bbes" date="1258059686"]I use the same approach as the op but i would like to know how your approach works whitey5759...
Could you post that "extension"[/quote]
Yeah sure. Couple of quick points:
* You only have to call parent::Controller() or parent::MY_Controller() is the constructor of a Controller which extends either Controller or MY_Controller respectively. You don't need it in your index() or login() functions, or anywhere else for that matter.
* I personally like to have a separate Controller and View for the login stuff, so I wouldn't have it in MembersArea. I think it just makes it too messy and more complicated than it needs to be. In fact, you'd have to detect what Controller and function is being called in the MY_Controller constructor, to make sure that if they are trying to view membersarea/login, then don't do the logic check first. That's kind of messy, so I've not done that in the below example.
Code:
//libraries/MY_Controller.php
class MY_Controller extends Controller
{
function MY_Controller()
{
parent::Controller();
//If the user is not logged in then proceed no further!
$is_logged_in = $this->session->userdata('is_logged_in');
if(!isset($is_logged_in) || $is_logged_in != true)
{
redirect("login", "location");
}
}
}
//controllers/membersarea.php
class MembersArea extends MY_Controller
{
function MembersArea()
{
parent::MY_Controller();
}
function index()
{
//This won't get called if the login check in the MY_Controller constructor fails.
//Instead the user will be taken straight to the login screen.
}
}
//controllers/login.php
class Login extends Controller
{
function Login()
{
parent::Controller();
}
function index()
{
$data['main_content'] = 'LogIn';
$data['title'] = 'Golf Club - West Yorkshire';
$data['h1'] = 'Golf Club - West Yorkshire';
$data['h2'] = 'Golf Club Members Area';
$data['BodyClass'] = 'MembersArea';
$data['FlashFile'] = 'crossfade_xml';
$data['Image1'] = 'Image1.jpg';
$data['Alt1'] = 'Pict1.jpg';
$data['Image2'] = 'Image1.jpg';
$data['Alt2'] = 'Pict2.jpg';
$data['Image3'] = 'Image1.jpg';
$data['Alt3'] = 'Pict3.jpg';
$data['Image4'] = 'Image1.jpg';
$data['Alt4'] = 'Pict4.jpg';
$this->load->view('template', $data);
}
function validateLogIn()
{
//.......
}
}