Should I make this a Different Module in HMVC Codeigniter?
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
- 'blog' - Blog/News Display
- 'auth' - User Authentication
- '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?
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.
精彩评论