Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Using a Model's function on a queried Simple object

Hi!

I have a model named User, and I cannot get any of its functions work whether I get the model from a query.

<?php
use Phalcon\Mvc\Model;

class User extends Model
{
    public $id;
    public $name;

    public function getSomeExtraData()
    {
        return 'something';
    }
}
?>

Whether I use User::find(), I cannot execute the getSomeExtraData() function on any of the returned Simple objects.



42.3k
Accepted
answer
edited Aug '15
Szasz :P

:find() returns a ResultSet (array).

foreach(Model::find() as $item) {
    $item->getSomeExtraData();
}

Also if you select some columns, it will always return Simple object(not actual object) beacause its not a full object.

Köszi ;)

Thank you for the fast answer! I was using the same method, and it turns out that it even worked, but I had a character encoding issue in a file...

Szasz :P

:find() returns a ResultSet (array).

foreach(Model::find() as $item) {
   $item->getSomeExtraData();
}