Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How get fields and data from ORM
  • Dear,

    When even i execute a query Find('all') or get_one()  i getting a big object,

    $query = Model_post::find('all');
    how i get post name and post id
    $query->id is sufficient, i is not working well.

    give me a best solution for that, for every query i done with orm, i need to use foreach.
  • HarroHarro
    Accepted Answer
    ORM has two methods of data retrieval, get() and get_one(). The find() method uses both, depending on the question asked. 'all' for example uses get(), 'first' uses get_one().

    get_one() returns a single model object, or null if nothing was found. get() returns an array of objects, or an empty array if nothing was found.

    This is why, in your above example, $query->id doesn't work. You ask for 'all', so you can get a list of thousands of ojbects, each with an id. So obviously you need to iterate over the list.

    If you want a single object, ask a question that returns one. So either find() with 'first', 'last' or with a primary key, or query() with get_one().

Howdy, Stranger!

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

In this Discussion