How to use the event aftersave?
I write in the model, but it is not invoked when saving data in the database.
public function aftersave ($ insert, $ changedattributes)
{
var_dump ("ooooooooo");
}
Here is my model:
& lt;? php
Namespace App \ Modules \ Userpanel \ Models \ Userpanel;
Use App \ Models \ DB_Table \ Tablename;
USE Yii \ Base \ Model;
USE Yii;
USE Yii \ Base \ EVENT;
USE Yii \ db \ ActiveRecord;
Class Form Extends Model
{
Public $ user_id;
Public Function Rules ()
{
Return [
['User_ID', 'Required'],
];
}
Public Function Aftersave ($ Insert, $ ChangeDattributes)
{
Parent :: Aftersave ($ Insert, $ ChangeDattributes);
var_dump ("ooooooooo");
}
Public Function AddZakazdb ()
{
$ MODEL2 = new tablename ();
$ model2- & gt; user_id = $ this- & gt; user_id;
Return $ model2- & gt; save ();
}
}
Answer 1, Authority 100%
You missed the parent method:
public function aftersave ($ insert, $ changedattributes) {
Parent :: Aftersave ($ Insert, $ ChangeDattributes);
// below your code
var_dump ("ooooooooo");
}
Why? Because we convey to the parent method all the same parameters and launch it, and then we do everything you need.