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

Phalcon Load object

Good afternoon, please can you help me to find solution, if i need to load model ?

For example i need to update model and call method of this model:

$user = \User::load($id);
$user->update_method( $field );
$user -> save();

In case if I use \User::findFirst() - returns \Phalcon\Mvc\Model and there is no way to call "update_method()" from "User" model.

If I use $this->modelsManager->createBuilder()->from('Users') - it returns Phalcon\Mvc\Model\Resultset\Simple.

Is there any way to get in result \User with loaded parameters ?



98.9k

In case if I use \User::findFirst() - returns \Phalcon\Mvc\Model and there is no way to call "update_method()" from "User" model.

Where is update_method() implemented?

edited Aug '14

It's a public function in class Users extends \Phalcon\Mvc\Model



98.9k

It must work, do you have something like this?

class Users extends \Phalcon\Mvc\Model
{
    public function update_method()
    {
        $this->name = 'something';
    }
}

What error are you getting?



2.2k
Accepted
answer

I got! The problem was in columns !

When you trying to call FindFist and set columns it will return Phalcon\Mvc\Model\Row or if you will call FindFirst without column set, in will return object of your model and you can call your methods.

Thank you )