We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Collection Getter & Setter

I am working with the Phalcon ODM and can't find a solution for following problem: There are many fields. I am always working with a different set of fields. Not every field is stored by default. I need a solution to work with getters and settern for manipulating a result. For example:

class Categories extends Collection {

    public $count;
    public $name;
    public $slug;
    public $parent_id;
    public $active;

    // Is this possible???
    // This would render "0" if the $count is empty
    public function getCount() {
       if(empty($this->count()) { $this->count = 0;  }

Thank you!


Okay, I answered the question by my own. I solve this issue with the afterFetch event:

public function afterFetch()
    if(empty($this->count)) { $this->count = 0; }