[eluser]cahva[/eluser]
The purpose of __autoload is that when using PHP5, it will automatically load your classes from the libraries folder if they are the same name. When using this __autoload, you dont actually need MY_Controller at all.
Put the autoload to the config.php as suggested.
Create Admin_Controller.php to libraries folder.
Code:
class Admin_Controller extends Controller {
function __construct()
{
parent::__construct();
// Do something here eg. check if logged in
$this->load->library('ion_auth');
if (!$this->ion_auth->logged_in())
{
redirect('login');
}
}
}
Create Site_Controller.php to libraries folder.
Code:
class Site_Controller extends Controller {
function __construct()
{
parent::__construct();
// Do something else here. Maybe load some helpers, Create content that you need sitewide etc..
}
}
Then in controllers you extend from one of those. Normal pages would use Site_Controller and pages that needs authenticated user extends from Admin_Controller.
controllers/home.php
Code:
class Home extends Site_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('home');
}
}
controllers/backend.php
Code:
class Backend extends Admin_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('backend');
}
}
Try it. Should work(unless I had some typos
). BTW, base controllers dont use index() methods. And always use __construct as constructor(you had some mixed constructors with PHP4/PHP5 style in your code).