HMVC Requests

HMVC requests are a great way to separate logic and re-use controller logic in multiple places. One common use of this is when you use a theme or template engine to generate your pages, where every page is divided into sections, and sections are populated by widgets. By using modules to produce the widget output, you can create a highly modular application, with easy to re-use components.

You call a module controller method using the Request class:

By default, all requests made are processed by Fuel's routing engine. If you want to request something that isn't routeable (for example because you don't want a browser to request it) you should pass 'false' as second parameter to the factory call. If you don't you will end up with a 404 error when you execute the request!

Loading views in HMVC request is the same as in normal requests and controller accessed by HMVC request are also approuchable via the browser. In some cases, for example widgets, are not suppose to accessed through the browser. In those cases you'll want to check if the request is made through HMVC or the browser. The following example shows you how to check for a HMVC request: