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

Custom methods in Model class

Hi guys, it's me, again :)

I have a code in OfficeController:

public function productsAction() {
    ...
    $products = MarketProducts::forOffice($categoryId);
    ...

And code in MarketProducts model:

public function forOffice($catId) {

    $products = self::find([
        'category_id = ?0 and published_office = 1',
        'bind' => [$catId],
    ]);

    return $products;
}

but i catch exception: Exception: Call to undefined method OfficeController::getschema()

Why OfficeController::getschema, but no MarketProducts?

How right write a own methods in Model class?

edited Sep '17

It should be static method in your case. Im not sure about this error, it's weird.

Also just do:

return self::find([
        'category_id = ?0 and published_office = 1',
        'bind' => [$catId],
    ]);