[eluser]cryogenix[/eluser]
Add this at the bottom of application/config/config.php:
Code:
/*
| -------------------------------------------------------------------
| Native Autoload - by Phil Sturgeon.
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
| If using HMVC you do not need this! HMVC will autoload.
|
| Place this code at the bottom of your application/config/config.php file.
*/
function __autoload($class)
{
if(strpos($class, 'CI_') !== 0)
{
@include_once( APPPATH . 'libraries/'. $class . EXT );
}
}
then make custom controllers in your application/libraries folder like this Protected_Page_Controller:
Code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Protected_Page_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
if(!$this->ion_auth->logged_in())
redirect('auth/login', 'refresh');
}
}
/* End of file Protected_Page_Controller.php */
/* Location: ./application/libraries/Protected_Page_Controller.php */
then finally, simply extend this with any other controller that needs the authentication check:
Code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends Protected_Page_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
//do something here
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */