Welcome Guest, Not a member yet? Register   Sign In
Admin versus Member Question
#1

[eluser]TerryT[/eluser]
Asking for some advice from anyone that has dealt with this issue before. My app has admins and members. Obviously the admins have more options than the members. For example, the admin can look at all their projects and all their members in those projects. The members can only look at the projects they are involved in and can't look at other member's items. This pattern follows throughout the app. Admins can add members. Members can only edit their profile, etc.

Following good MVC practice, would you code separate views for the admins versus the members? Or would you just use some if statements to decide whether to show the additional menue items, drop down boxes, etc. if the person is an admin? And even if it doesn't follow strict MVC, what actually works?

Thanks in advance.

Terry
#2

[eluser]InsiteFX[/eluser]
I would have different controllers and views so that it is easy to update things.

InsiteFX
#3

[eluser]TerryT[/eluser]
Thank you for the guidance. I was leaning that way, but still beating my way through using MVC and objects. Coming from a procedural background, it has been a little tough to start. Worried about the code duplication in the views and was it "best practice". Thanks again.

Terry
#4

[eluser]Watermark Studios[/eluser]
I agree with InsiteFX. Also, if you use separate controllers, you can do your admin verification in the constructor of the controller, which means you don't have to check if the user is admin for each method.
#5

[eluser]InsiteFX[/eluser]
Here is a good article to read by Phil Sturgeon.

Keeping it Dry

InsiteFX
#6

[eluser]TerryT[/eluser]
Thanks for the help and the reference to the DRY article. It makes sense now. Only thing I didn't understand was the need for the autoload function in config.php:

Code:
/*| -------------------------------------------------------------------|  Native Auto-load| -------------------------------------------------------------------| | Nothing to do with cnfig/autoload.php, this allows PHP autoload to work| for base controllers and some third-party libraries.|*/

function __autoload($class){ if(strpos($class, 'CI_') !== 0) {  @include_once( APPPATH . 'libraries/'. $class . EXT ); }}

I looked up the function in the php manual and some Google entries and understand that it eliminates a bunch of includes. But I am having trouble wrapping my head around why it is needed. Can someone help and explain what is going on and why? Thanks.

Terry
#7

[eluser]InsiteFX[/eluser]
It's autoloading all the libraries in libraries folder
so that you do not need to load them.

It's just a native autoloader.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB