ServAce85
ServAce85

Reputation: 1622

To Nest or Not to Nest? MVC Controllers (CodeIgniter)

Background:

I'm having some trouble understanding exactly how to best use controllers in an MVC architecture.

I have a webapp that follows this URL scheme:

*Note: This URL structure is similar to StackOverflow's in that malformed URL's (wrong event-names) are automatically corrected if the id# exists.

Question:

Since categories, users, and event-types each have unique functionality associated with them (i.e. editing users, manipulating events, etc.), they are all contollers of their own (right?). And since event-type-A and event-type-B are very similar, they share common functionality extended from an events class.

How do you suggest that I organize my controllers such that they follow "standard practice" in OOP and MVC design?

I currently have a Pages class for my static pages, and I was expecting to have a categories class that calls a users class, event-type-A and event-type-B classes that (as described above) are extensions of an events class... but from here I'm unsure of how best to proceed.

Any simple/pseudo code examples would be greatly appreciated.

Additional Information:

FYI: I am using PHP/MySQL. I have been trying to learn MVC by writing my own framework, but have recently switched over to CodeIgniter. That being said, either a CodeIgniter specific solution or a general MVC solution will suffice.

Update:

As Ako mentioned below, I could definitely have the events combined into a single controller and then have the two types spawn from that. I am just confused as to how I actually set up each of the controllers (which methods to define, etc.) to make them work together properly.

Upvotes: 0

Views: 270

Answers (2)

ServAce85
ServAce85

Reputation: 1622

It looks like this answer offers a solution that is satisfactory.

In essence:

Use HMVC to load necessary MVC triads when desired.

I had never heard of HMVC before, but apparently it will allow me to designate when certain MVC triads are called which will ultimately give me control over when different Controllers are called. This will allow each of the sections (categories, events, types, etc.) to act as independent modules that have their own index pages that can be called, but can also offer the ability to serve much more elaborate data as needed.

Upvotes: 1

Omid Kamangar
Omid Kamangar

Reputation: 5778

How about changing /categories/event-type-A and /categories/event-type-B to /categories/events/type? Where type could be one of A or B (or something like that)?

Upvotes: 0

Related Questions