Welcome Guest, Not a member yet? Register   Sign In
Best Practices HMVC?
#2

(This post was last modified: 04-22-2015, 06:34 AM by kilishan.)

I'm not a big fan of calling controllers like that, personally. In CodeIgniter the solutions that I've seen will confuse the framework a bit, as it's not intended to be used that way.

From all of my reading about HMVC over the years, there are two "valid" reasons to use that type of a system:

The first is for scaling purposes, allowing you to convert an internal request to an external request (on a different server) very easily, as referenced in this article. That's a perfectly valid use case, though one that neither of the CI-based solutions that I'm aware of will handle.

The second, and the main reason that I see people asking about this, is for a form of "widgetization" of content, to keep content clean and organized. A noble idea. I just don't believe that controllers are the place for that.

Part of that is purely from an architectural stand-point: controllers have one very real purpose: control the flow of information between the model and view layers. That's basically it. I'm aware it could be argued that it's still solving that issue. The other, larger, part is the very real danger of confusing your code between the separate "requests". When you load up that controller again, all of your constructor items will happen again. So, if you're using different base controllers, which I very much advocate for, then all of their process will fire again, even though they already fired. First, that's unneeded overhead. Second, the CI instance is a singleton and any processes in your controller constructor process would have to be extremely careful not to change anything that could mess with the primary request object, since they're the same thing. While it's doable, it can make debugging some things much more challenging then they need to be.

So, what's the solution? Use a library or other namespaced class to handle it. Calling a single class' method is no different that use Modules::run(). If you use a namespaced class instead of a CI library, it's even cleaner. To clean things up even more, create a single Widget class that is called that can then find the correct class/library. I do something similar in my template layer for Sprint, using "view callbacks".
Reply


Messages In This Thread
Best Practices HMVC? - by frocco - 04-22-2015, 05:33 AM
RE: Best Practices HMVC? - by kilishan - 04-22-2015, 06:34 AM
RE: Best Practices HMVC? - by frocco - 04-22-2015, 06:45 AM
RE: Best Practices HMVC? - by kilishan - 04-22-2015, 07:07 AM
RE: Best Practices HMVC? - by frocco - 04-22-2015, 07:15 AM
RE: Best Practices HMVC? - by kilishan - 04-22-2015, 07:24 AM
RE: Best Practices HMVC? - by frocco - 04-22-2015, 07:41 AM
RE: Best Practices HMVC? - by kilishan - 04-22-2015, 07:44 AM
RE: Best Practices HMVC? - by frocco - 04-22-2015, 08:37 AM
RE: Best Practices HMVC? - by kilishan - 04-22-2015, 09:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB