Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How getting an array from the Model
  • Hello people,

    I don't get it. I have at the moment this at the end of the controller

    $this->template->title = "Sales";
    $this->template->content = View::forge('sales/create');
    //  echo '<pre>'; var_dump(Model_Reporter::find('all')); echo '</pre>'; exit(0);
    //  echo '<pre>'; var_dump(DB::select()->from('reporters')->execute()->as_array()); echo '</pre>';
    $view->set_global('reporters', Arr::assoc_to_keyval(DB::select()->from('reporters')->execute()->as_array(), 'id', 'name'));

    Is there a way to do something like

    Model_Reporter::find('all')->to_array(); ?!

    Thank you 4 every answer :)

    Greetings Terrah4wk
  • HarroHarro
    Accepted Answer
    an ORM, as the name implies, creates objects, not arrays. In this case, an array of objects, since find('all') returns multiple results.

    You can call to_array() on an ORM object without problems, but you can't have the ORM return the result as an array, it's not designed to be a query builder.

Howdy, Stranger!

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

In this Discussion