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.

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; }