Question

What is the best way to build a page in FuelPHP so that each of the blocks of the page are built on their own as modules and then the output HTML is put together in a layout.

The best i have found thus far is the HMVC with something like the below.

$block1= Request::forge('mycontroller/block1')->execute();
$block2= Request::forge('mycontroller/block2')->execute();

$data['block1'] =$block1;
$data['block2'] = $block2;

//assign the view to browser output
return View::forge('home/index', $data);

However loading up the whole framework for the calls seems rather inefficient (and possibly slow as a result) . Is there a better way to do this?

Was it helpful?

Solution

If you're using modules (instead of calling a different action in the same controller like you seem to do here), requests are absolutely the way to go. And since requests use the routing table, you can control which controller/action is called by manipulating your routes.

Setting up a new request isn't very complex, the additional delay is a few milliseconds tops.

For completeness, the way to perform an HMVC request:

try
{
    $result = \Request::forge('your/uri/here')->execute()->response()->body;
}
catch (\HttpNotFoundException $e)
{
    // the requested URI could not be found
}

OTHER TIPS

Instead to use Request::forge('mycontroller/block1')->execute(); you can use View::forge('mycontroller/block1').

The view must be proccess the blocks, not the request. Other advantage is pas vars to block.... i've not tested completely, but it seems more fast to render.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top