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

How can I prevent all queries based on a condition?

I want to prevent all INSERT and UPDATE queries based on a user_id



2.1k

Can you elaborate what you are trying to establish?

if you are trying to prevent a certain user from doing anything at all in your website. i suggest ACL. if you are trying to stop a model from updating/inserting if it was fetched from a userid. extend the findfirst and find and throw exception when a user only provides id.

In my application I need a demo user that cannot change anything in database, only login.



2.1k
Accepted
answer
public function beforeValidation()
{
    if($this->session->get("user_id") == ??)
    {
        return false; // or true
    }
}

https://docs.phalcon.io/en/latest/reference/models.html#events-and-events-manager

make use of event to stop the insert/update

Awesome. Perfect. Amazing. Thanks.