CodeIgniter Forums

Full Version: Am I understanding HMVC correctly?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]kimp[/eluser]
I'm working toward a complex application and I think that eventually I'll need HMVC, but not sure.

In essence, I have many views where there will be several sub-views, each with their own logic and functionality. In fact, each of the sub-views is equivalent to a separate controller function.

The best example is where an Admin selects a user from a list, and goes on to edit that user. I currently have two controller functions: one for listing users, one for editing the chosen user. If I want to put these on the same page, however, I think I need to use HMVC. Is that right?

At first I thought it was simply a matter of one sub-view using ajax to requery the second sub-view, but now I realise that the sub-views are more than just 'views', they are actually controller functions.

Not sure if this makes sense, but any clarification would be appreciated!

El Forum

[eluser]dudeami0[/eluser]
HMVC basically allows you to chunk up your application into smaller sections. So you can have one module named "admin" for all admin related stuff, another the users control panel. For each module you make a controller, and for each page in that module you add a method to handle that page.

From what your saying, your trying to chunk it up a little far in my opinion. How you could set it:

Code:
class Admin extends Controller {
  
   function index() {
      // Load the page here
   }
  
   function viewusers() {
      // Use this to get the HTML to load into the page
   }

   function edituser($id) {
      // User this to edit the user
   }

}

With index being a shell, and viewusers and edituser loading into the index with ajax or just use then as pages. You might want to look around the web and read up a little more on HMVC and MVC to get a better idea on how to chunk up your modules and such.

Edit: This article might be of some help.

El Forum

[eluser]kimp[/eluser]
Thanks dudeami0. Good explanation. Good article too.