Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
how to get a detail value from a find return ?

  • $items = Model_Item::find($id, array('related' => array('images')));
    $result = $items->to_array();
    The output of $items is below ,I wonder  how to get the image file_name ?
    array(18) {
    ["id"]=>
    string(2) "27"
    ["product_code"]=>
    string(3) "666"
    ["item_color_id"]=>
    string(1) "7"
    ["item_size_type_id"]=>
    string(1) "1"
    ["classification_id"]=>
    string(1) "1"
    ["name"]=>
    string(5) "66666"
    ["display_name"]=>
    string(8) "goods_18"
    ["usual_price"]=>
    string(5) "88888"
    ["selling_price"]=>
    string(3) "888"
    ["point_ratio"]=>
    string(2) "88"
    ["description"]=>
    string(3) "888"
    ["publish_start_datetime"]=>
    string(19) "0000-00-00 00:00:00"
    ["publish_end_datetime"]=>
    string(19) "0000-00-00 00:00:00"
    ["publish_flag"]=>
    string(1) "8"
    ["created_at"]=>
    string(19) "0000-00-00 00:00:00"
    ["updated_at"]=>
    string(19) "0000-00-00 00:00:00"
    ["deleted_at"]=>
    NULL
    ["images"]=>
    array(1) {
    [6]=>
    array(6) {
    ["id"]=>
    string(1) "6"
    ["file_name"]=>
    string(36) "ea4c6011154b543e710b8809ed39b9db.jpg"
    ["content_type"]=>
    string(10) "image/jpeg"
    ["created_at"]=>
    string(19) "0000-00-00 00:00:00"
    ["updated_at"]=>
    string(19) "0000-00-00 00:00:00"
    ["deleted_at"]=>
    NULL
    }
    }
    }
  • HarroHarro
    Accepted Answer
    From the looks of it, images is a one-to-many relation, so you have to loop.

    foreach($items['images'] as $pk => $image)
    {
        echo $image['file_name'];
    }

Howdy, Stranger!

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

In this Discussion