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.

How can I prevent all queries based on a condition?

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



1.4k

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.



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

http://docs.phalconphp.com/en/latest/reference/models.html#events-and-events-manager

make use of event to stop the insert/update

Awesome. Perfect. Amazing. Thanks.