We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.



77.7k
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.



1.4k

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();
}