Welcome Guest, Not a member yet? Register   Sign In
Routing a user based on their role.
#1

[eluser]behdesign[/eluser]
I have a team-management project for a client, and I've created a series of models that inherit from an abstract 'member' model. I want to create a controller cascade where the 'member' controller checks for the type of team member it is (client, support staff - based on their userid) and reroutes the user to the appropriate controller for their home page.

Is this better accomplished in routes, or in the member controller?

Thanks!
#2

[eluser]bretticus[/eluser]
The routes way simply takes a URL and routes it internally (ex. map /bob to /members/bob) You can use limited logic here and really this is just for aesthetics when it boils down.)

Your controller is the spot for business logic really. Determining what a user can see depending on his or her membership role certainly falls into business logic in my opinion. I see no problem with using simple redirects or just showing different views based on role.
#3

[eluser]Colin Williams[/eluser]
It depends on what your User API looks like, and how you've structured your controllers. Like bretticus said, it might be enough to just sprinkle logic throughout the controller to server up different data and different views. Also, you can do a lot with the _remap() function
#4

[eluser]behdesign[/eluser]
Is there such a thing as an abstract controller in CI?

Or would I extend the base Controller class with, say Member_Controller(), then inherit the individual member-type controllers from that (class Staff_Controller extends Member_Controller)?
#5

[eluser]Colin Williams[/eluser]
Whatever you can do in PHP, you can do in CodeIgniter. Just note that if you don't stick to CI's conventions, you'll have to load the required files yourself.
#6

[eluser]bretticus[/eluser]
CI has a PHP 4 approach to extending core classes. That is, CI checks for the existence of a MY_ prefixed version of the core class and uses it if it exists. You simply extend the core class to get all the functionality of that class and then make the changes/additions that you need. Yes, you can extend the controller class in this manner (if you want to break with the framework PHP 4 paradigm, you can autoload classes a la PHP 5. There are tutorials out there but I assume that include is probably comparable for performance.)

According to the PHP manual:

Quote:Any class that contains at least one abstract method must also be abstract.

Thus, I don't think you want to make an abstract class to replace controller. Either extend the controller class with a MY_ version or build a standalone library file (Member_Controller) that extends the controller class. If you really want an abstract class to inherit role classes from, just build one independent from controller functionality and call it in your controller constructor.




Theme © iAndrew 2016 - Forum software by © MyBB