那个能帮我解释哈代码 [ 2.0 版本 ]
这段是干嘛的
'on beforeRequest' => function($event) {
\yii\base\Event::on(\yii\db\BaseActiveRecord::className(), \yii\db\BaseActiveRecord::EVENT_AFTER_UPDATE, ['backend\components\AdminLog', 'write']);
},
还有 下面 $event 是啥
<?php
namespace backend\components;
use Yii;
use yii\helpers\Url;
class AdminLog
{
public static function write($event)
{
if(!empty($event->changedAttributes)) {
$desc = '';
foreach($event->changedAttributes as $name => $value) {
$desc .= $name . ' : ' . $value . '=>' . $event->sender->getAttribute($name) . ',';
}
$desc = substr($desc, 0, -1);
$description = Yii::$app->user->identity->username . '修改了' . $event->sender->className() . 'id:' . $event->sender->primaryKey()[0] . '的' . $desc;
$route = Url::to();
$userId = Yii::$app->user->id;
$data = [
'route' => $route,
'description' => $description,
'created_at'=>time(),
'user_id' => $userId
];
$model = new \common\models\AdminLog();
$model->setAttributes($data);
$model->save();
}
}
}
大头 补充于 2016-12-03 13:28
奥 谢谢
共 1 个回答
大头
注册时间:2016-11-14
最后登录:2017-07-10
在线时长:9小时42分
最后登录:2017-07-10
在线时长:9小时42分
- 粉丝7
- 金钱330
- 威望0
- 积分420