Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
My HMVC request gets converted to string
  • I have a template controller with this method. public function action_index() {
    $this->template->title = 'Dashboard';
    $this->template->items = Fuel\Core\Request::forge('journal/jlist/journal_list')
    ->execute();
    } here is app/classes/controller/journal/jlist class public function action_journal_list() {
    $view = \Fuel\Core\View::forge('journal/journal_list');
    $view->journal_items = Model_Journal::load_journals(); return $view;
    } When I run to the template class, my request turns into string with " <php loop statement> " see http://screencast.com/t/PAtLYHyQj1r to see the result. Thanks.
  • execute() on a Request object results in a Response object returned. The objects contents (the return value of the HMVC call) will be converted to string by the Response objects __toString() method as soon as you try to echo it out. Normally you want to fetch the response body from an HMVC call, not the complete Response object. Secondly, by default everything you send to a view for display will be encoded for security reasons. If you have something that shouldn't be encoded you'll have to pass it to a view using the set_safe() method. View and Viewmodel objects are whitelisted, they will not be encoded. Use this to solve both of them:
    // get the View object from the response body and assign it to the template
    $this->template->items = \Request::forge('journal/jlist/journal_list')->execute()->response()->body;
    

    p.s. Never use the \Fuel\Core namespace, all Fuel core classes are available in the global namespace. If you do you'll get into trouble when you want to extend a core class.
  • Ok got it, thanks!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion