pick between two controllers from one URL |
[eluser]Eric_WVGG[/eluser]
I have a controller class called List. It is extended by a bunch of subclasses — including List_all and List_mine — which provide different database queries and output handling to List. I need my base-level URL (http://mysite.com/) to serve List_all if the user is not logged in, and List_mine if a login is present. If I were not working within CodeIgniter, I'd do something like... Code: if( $is_logged_in ) $page = new List_mine; So, thoughts?
[eluser]WanWizard[/eluser]
Yes, don't try to solve this using controllers. Controllers in an MVC pattern are, as the name implies, only meant to control the flow from URI request to output. This is a classic case for two different models, which are meant to house all your data handling code. If you want to do the same as above, you could do: Code: // load the correct page model based on the logged-in state
[eluser]bretticus[/eluser]
Yeah, your implementation is very inadvisable. You are using controllers for which uses controllers are not meant. The only definition of a controller from the user manual is: Quote:A Controller is simply a class file that is named in a way that can be associated with a URI. It really shouldn't be doing things that libraries and models are meant to do. You can quite easily (and should) put this functionality into your models. I know people extend stuff like security into controllers, but that tends to lead to bad design that puts you in situations like this.
|
Welcome Guest, Not a member yet? Register Sign In |