Has anyone ever used the hook function of tp5? The lack of information on the Internet is appalling. How can I use it in this case?

is actually very simple. If anyone who has used tp3.2 and knows this requirement has the hook function before 3.2, I used to use it very comfortably, so I turned to 5.0, and I was also looking for ways to use it. I know that there is no hook. Now it is an event, and there is documentation, so I will write it as follows

protected static function init ()

{
        Ad::event("before_insert", function ($user) {
            $user->addtime=time();
    });
    Ad::event("before_update", function ($data) {
        $data->uptime=time();
    });
}



beforecurdbeforeafter



protected static function init()
{
        Ad::event("after_insert", function ($user) {
            $user->addtime=time();
    });
    Ad::event("after_update", function ($data) {
        $data->uptime=time();
    });
}

3.2after insert$dataidid5.0


< hr >
   **before**
Php
Jun.29,2021

it was carried out, you just didn't realize it.
you should see

as soon as you dump.
    dump(111);
   $user->addtime=time();
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-1b386ea-2b478.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-1b386ea-2b478.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?