4

I'm just getting started using HMVC in Codeigniter. The main module is a news/blog site called 'blog'. I want users to be able to log in to comment, so I have authentication files (tank auth actually). Now I also want the users to have their own profile pages which shows their posting stats and personal info. Users can also have a Private Message system where they send messages to each other.

Being new to HMVC, how should I modularize my code? I'm currently guessing a good one will be

  1. 'blog' - Blog/News Display
  2. 'auth' - User Authentication
  3. 'users' - User profile + Private Message

Both 'blog' and 'users' will be calling 'auth' which also displays a little widget at the corner of the page that shows Sign up | Register if not logged in, and Welcome John! Profile | Inbox | Settings if logged in as John.

Or should I combine 'auth' and 'users' together, or split 'users' into 'profile' and 'messaging'? How will the hierarchy be like if you were to design the HMVC structure?

Nyxynyx
  • 61,411
  • 155
  • 482
  • 830

1 Answers1

1

It really depends, and it's up to you.

If you want the comment system to apply to other modules some day, definitely make it it's own module. If it's only related to blogs, you could leave it in the blogs modules as it's own controller. This is also where modules::run() and $this->load->module() can come in handy, calling a controller from anywhere to get view fragments, to display the comments.

I would probably make everything it's own module.

It's pretty much impossible to be truly 100% modular, there will always be certain dependencies. The best thing you can do is try to organize it in a way that makes sense to your particular project. In general, modularize as much as possible - if you decide to get rid of blog comments some day, you can just delete the comments module.

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • I did some planning and thinking of the modularization and notice that I can only have 1 controller for each HMVC module? I concluded this since the module name has to be same as the controller name/filename. Is this true? – Nyxynyx Jun 08 '11 at 01:53
  • 1
    It's not true. You can have as many controllers as you want. For instance, a "comments" controller within the "blogs" module, accessed by the url `/blogs/comments/comment_method` – Wesley Murch Jun 08 '11 at 02:42
  • I understand now. In other words, the default controller for the "auth" module will be the "auth" controller, which can be accessed via /blogs/auth as well as /blogs/auth/auth – Nyxynyx Jun 08 '11 at 03:24
  • 1
    Your auth module should not be within your blogs module - I'm not sure what you mean by that - so no. However, you are right about the first part. The default controller name matches the module name, but other controllers can be accessed as well. For example, if I have two controllers in my `blogs` module called `blogs` and `comments`, I can access `comments->index()` by `/blogs/comments`. I know you are using tank auth, so really the only thing you should be doing with it is logging in and out and managing users. Care to explain more what you are trying to do? – Wesley Murch Jun 08 '11 at 03:37
  • Right sorry for the confusion, my auth module is not within the blogs module, i included '/blogs' into the exmaple url by mistake. I'm just implementing tank auth into the system to allow visitors to interact with the site by leaving comments and interact with each other via profiles and private messaging. Thank you, cleared up my many doubts! – Nyxynyx Jun 08 '11 at 04:01