Welcome Guest, Not a member yet? Register   Sign In
where should I position my extended controllers?
#1

[eluser]bill19[/eluser]
Hello ,

I am planning to use extended controllers for the first time.

right now I have:

Code:
class  MY_Controller  extends CI_Controller  {

    
        
}
    
        
class Admin_Controller extends MY_Controller {

    
}

class Common_Auth_Controller extends MY_Controller {

    
    
}

All in 1 file called MY_Controller.php in the application/libraries folder. Is this the best practice?

Thanks,

Bill

#2

[eluser]CroNiX[/eluser]
Extensions to the core, like CI_Controller, go in /application/core. The file must be named MY_Controller.php, and CI will autoload it when a controller is called.

CI like to have 1 class per file. If you want more extensions than 1 level, I'd suggest reading Phils article on Base Classes and check out how he autoloads them.
#3

[eluser]Ajaxboy[/eluser]
3 classes in 1 file extending the CI_Controller class.. not good practice
#4

[eluser]bill19[/eluser]
I am having trouble redirecting to my extended controllers, including my Home controller. I have placed them all in /application/core. However:

Code:
redirect('/application/core/Home');

does not work.

my url string reads:

Quote:http://localhost/auth/index.php/application/core/Home

Thank you,

Bill
#5

[eluser]CroNiX[/eluser]
You misunderstand. Only MY_Controller (which extends CI_Controller) goes in /application/core.

The rest of your controllers just go in /application/controllers like normal, but they extend MY_Controller instead of the normal CI_Controller. You can't direcly access anything in /application or /system from the URL. Those are protected. You just use the regular CI urls.

Like
Code:
redirect('controller/method');
echo anchor('controller/method', 'My Anchor');
//etc.
#6

[eluser]bill19[/eluser]
Hi CroNiX,

Thanks for clarifying that. I've got it working now.

best regards,

Bill




Theme © iAndrew 2016 - Forum software by © MyBB