Welcome Guest, Not a member yet? Register   Sign In
master controller for common tasks?
#2

[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 */


Messages In This Thread
master controller for common tasks? - by El Forum - 04-11-2011, 11:57 PM
master controller for common tasks? - by El Forum - 04-12-2011, 12:18 AM
master controller for common tasks? - by El Forum - 04-12-2011, 01:44 AM
master controller for common tasks? - by El Forum - 04-12-2011, 02:17 AM
master controller for common tasks? - by El Forum - 04-12-2011, 06:08 AM
master controller for common tasks? - by El Forum - 04-12-2011, 12:06 PM
master controller for common tasks? - by El Forum - 04-12-2011, 08:05 PM
master controller for common tasks? - by El Forum - 04-14-2011, 03:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB