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

Binding where conditions for all CRUD

i need to bind for all my CRUD operations a dynamic where condition depends on user role, and i want to make this in one place if is possible



51.2k
edited Jun '14

check out "afterFetch" method in models. It might help. Eg: Create a base model and extend all your models from that one

class BaseModel extends \Phalcon\Mvc\Model
{
    public function afterFetch()
    {
        if ($this->user_role == 'admin') {
            // do something
        }
    }
}