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.

Magic methods aren't working

My code throws an exeption "PhalconException: The method 'findFirstByTitle' doesn't exist on model 'Plant'"

How can I fix it? Code:

class Plant extends \Phalcon\Mvc\Model {

public $id;
public $title;

protected function beforeSave() {
    if(empty($this->id) && $plant = self::findFirstByTitle($this->title)) {
        $this->id = $plant->id;
        return false;
    }
}

}

P.S.: I also tried to use $this-> instead of self:: with no success. PHP version: 5.4.43 Phalcon version: 2.0.6

Thanks.



12.6k
Accepted
answer
edited Oct '15

try

self::findFirst("title = '$this->title'");


1.1k

Thanks, mate. Your solution doesn't provide escaping of a title, so I used this code: self::findFirst(array('title' => $this->title));