문제

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?

도움이 되었습니까?

해결책

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
}

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top