views:

34

answers:

1

hello

i want to build a project using codeigniter, the project conisist of 2 levels, USER level and ADMIN level

i'm now building the ADMIN level, is it the best practice to make all my admin functions in 1 controller ? like add/modify/delete users and add/modify/delete admins etc....

or make many controllers everyone has it's job like one for add/modify/delete users and another controller for add/modify/delete admins .. and so on ?

i think the second choice is better but then i will have another problem, which is separating my user level controllers from the admin level controllers

Thanks

A: 

Personally it all comes down to preference. I prefer the method of creating an admin folder in my controllers folder so accessing my controllers for the admin area happens like so:

http://www.exampleapp.com/admin/clients
admin is the folder name in your controllers folder
clients is the name of the controller within the admin folder

The above URL structure has it's advantages and disadvantages (I prefer it to keep my code clean and less cluttered).

I tend to also make one model per table in the database. So a model called users would deal with all aspects of the users table in my database. A products model would deal with all aspects of the products database table.

You're still adhering to the DRY (don't repeat yourself) method because you simply include the model files you need from within your admin controllers depending on what section of the admin you're administering.

For your users section you could create a folder called users within your controllers folder and use the same above mentioned method.

Phil Sturgeon (a.k.a God of Codeigniter) summed this up in his blog post, but goes into a little more detail, give it a read: http://philsturgeon.co.uk/news/2009/07/Create-an-Admin-panel-with-CodeIgniter

Dwayne