Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Accessing data return from Model_....::query()
  • I have the following line of code:
    $entry = Model_Tmfleet::query()->where('tmfleet_name', $tmfleet->tmfleet_name)->get_one();

    Now, I want to get the 'id' from $entry...
    The only way I know I can do this is using a foreach loop, given that the model returned has an iterator.. But that doesn't seem right, as I'm only getting one model. e.g:
    foreach ($entry as $e) {
        $id = $e;
        break;
    }

    How can I access the data directly?

    ...Alternatively, I would have like to get just the value from the id column from the table using DB::query().... But my problem is the same... When I get the result, I cant access the data doing:
    $result->id... nor $result['id']..    ... or can I?

    Thanks..
  • rodas007rodas007
    Accepted Answer
    $entry = Model_Tmfleet::query()->where('tmfleet_name', $tmfleet->tmfleet_name)->get_one();
    $entry_id = $entry->id;
  • http://fuelphp.com/docs/packages/orm/crud.html#/find_chaining...()->where('table_field', $value)->get_one();vs...()->where('table_field', $value)->get();
    get_one() only returns one ORM Model object. Not need to iterate. get() returns an array of ORM Model objects, then it's time to use a for loop or whatever.


Howdy, Stranger!

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

In this Discussion