zrac
zrac

Reputation: 153

Auth code structure in CodeIgniter

I'm using CodeIgniter and Ion auth to develop a small web app. The app has 3 distinct types of users:

(imagine they are news entries)

I have a News Controller that add, list all, consult, delete and the respective Views.

By now, I have my Controllers organized this way:

Controllers:

So after the login the user is redirected to the respective News Controller.For instance, Author News Controller has Add, View And Consult functions, and NormalUser News Controller only has View and Consult functions.

What's bothering me is that must be a simple way to organize that, give different permissions, depending on the type of user. Is it supposed to repeat certain code?

And the Views? The header will be different depending of the user. Should I use the same header template with some if statements to show different data, depending of the user, or should I repeat the views in packs, changing the header?

Views:

In this moment I have a template folder with header.php and footer.php, but I have the problem of the different headers.

Upvotes: 1

Views: 279

Answers (1)

SwiftD
SwiftD

Reputation: 6069

No No No No No. Alarm bells should be ringing the second time you do (almost) the same thing, let alone the third or forth.

1 header/footer view with a few if statements absolutely. Probably the same with list and anything else where half the code is repeated.

And unless they are radically different, don't use three different news controllers either. Again, use control statements to direct the program flow, you should be checking for appropriate access levels within your individual controllers anyway. Dont just do it once in a master controller and redirect, those controllers can be accessed directly though URL.

I cant really put any code in here to help, but make a start and come back if you have any problems. Also, may be worth posting some code over at code review https://codereview.stackexchange.com/ to get some tips on how to adopt DRY software development

http://en.wikipedia.org/wiki/Don%27t_repeat_yourself

Upvotes: 2

Related Questions