Model events such as TP5.0 before_insert are invalid?

follow the ThinkPHP5.0 official manual prompt:

User::event("before_insert", function ($user) {
    if ($user->status != 1) {
       return false;
    }
});

:https://www.kancloud.cn/manua...

TP beforeInsert ,,,,.


the direct insertion is successful and is not affected by the pre-action. May I ask why?

Feb.28,2021

/ / insert
public function charu ($data)
{

return $this->insert($data);

}

changed to

/ / insert
public function charu ($data)
{

return $this->data($data)->save();

}
try it?

when you directly call the insert () method, you call the Model class, the parent class of the User class, but the Model class does not have this method, so you execute the _ _ Call method inside, pointing to the Query class (which does not bind your events). If you want to trigger the events on the User class, you must call the methods specified in the Model class to add, delete, modify and check these methods

.

didn't read the comments in the model event, did you? Didn't take a cursory look at the code, did you? Use the method in the model to insert and delete the data to trigger this model event, such as the save,delete method. But is the insert method an operation in the model? Methods in the db class do not trigger model events

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2bd3c-2bad0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2bd3c-2bad0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?