CodeIgniter Forums

Full Version: elegant way design controllers for medium-sized app?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I have an app where different roles can perform operations on the database. for example, the administrator can create people and manage people. People can manage themselves(people). Instructors need to view people and give people credit for attending a lecture.

So I have controller MAIN handling everything so far (I am new to OOP). Shouldn't I throw off control to a student controller and then test role for access to perform each method b4 they are allowed to perform it?

If so, what does that look like in my main controller?

OR, do I have the menu system simply point(link) to different controllers, like, you're in MAIN as an ADMINISTRATOR (so your URL is something like, Then have the menu link to <a href="student/manage">Manage</a> where that link takes the user to the manage method in the student controller and in that method, I test for authorization/access to be able perform that operation?

Starting to like this OOP stuff


El Forum

I would extend Codeigniter's Controller class with MY_Controller, build my auth system as a library that gets loaded in MY_Controller and performs its ACL checks in the constructor. I would then make sure that I'm putting logic that belongs in the model, in the model. The methods you use for "manage people" are going to be the same whether it's an Administrator or someone else doing the managing.

My controllers would then extend MY_Controller and handle a specific feature (or group of features).

El Forum

David, I understand that on a conceptual level. Being new to oop, I don't know what that looks like in actual code. Do you know of any links where I can see the code in action, of something similar to what you're talking about?

Many thanks.