Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

How to iterate "object" from $this->profiles_model->find_one()

Hi,
I want to get the array from $this->profiles_model->find_one() to have any record from profiles_model to take keys for the form. When I use foreach with this it doesn't iterate. I have checked that with gettype($any_record) and the result is "object". I can easily echo this object like a string (prints that it is an array, but it is not) or echo its nodes with echo $any_records->birth_date what returns correct values. But I want to iterate its nodes.
Even if I set the $return_method argument as "array" it doesn't return an array, but an "object" as above.
How to iterate that?

Comments

  • find_one() will return a single database record based on your $where criteria. By default it should be an array of nodes - each node being a database field.
    To iterate the nodes:
    foreach ($array as $key => $val) {
    echo "$key => $val \n";
    }

  • edited May 3

    I found that if you call find_one() function in the view file - then above problem appears.
    I believe that this function should be called in the controller.

  • Did you try find_one_array()?

  • Yes, but now inside the view files I'm using $object = fuel_model('module_name', 'one', array('id' => $some_id), 'precedence asc');
    This works fine.

  • You can also try $object->values() which will return an array of properties and values

Sign In or Register to comment.