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();
Menu