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.

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 ?



85.4k

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



85.4k

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?



1.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 )