Welcome Guest, Not a member yet? Register   Sign In
Multiple MY_Controller's
#1

[eluser]jasonjohnson[/eluser]
Is it possible to extend "Controller" in two (or more) different ways? The public side of the system I'm building needs distinctly different default controller functionality than the back-end does.

Currently, I have "MY_Controller" setup to handle the back-end default controller functionality. More or less looking for "My_Controller_Public" -- not sure if that's possible.

Anyone have an elegant solution to this?

Thanks.
#2

[eluser]Clooner[/eluser]
You could change the prefix(detect the url in the config file and change the prefix accordingly) making it front_controller and back_controller but this will only work if you have one controller extended. Or switch to using libraries.

Hope this helps,

Jeroen
#3

[eluser]xwero[/eluser]
Most people who use the Controller extension file don't stick to the one file one class rule of thumb.
Code:
class Backend extends Controller
{

}

class Frontend extends Controller
{

}
#4

[eluser]marcoss[/eluser]
Absolutely, here is a sampe of MY_Controller.php,

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Base_Controller extends Controller {
    public function __construct() {  
        //code here
    }
}

class Admin_Controller extends Base_Controller {
    public function __construct() {  
        //code here
    }
}

class Public_Controller extends Base_Controller {    
    public function __construct() {  
        //code here
    }
}

?>
#5

[eluser]jasonjohnson[/eluser]
Thanks all who replied, this gives me a much better idea as to how all this gets loaded. Much appreciate the sample code.
#6

[eluser]wiredesignz[/eluser]
Modular Extensions allows you to isolate parts of your website by using Modules. It also makes MY_Controller redundant by allowing you to autoload specific Controllers to perform initializing type tasks for others.




Theme © iAndrew 2016 - Forum software by © MyBB