rikcage / yii2-user-logs
用户日志操作 YII2
0.0.2
2019-01-31 14:09 UTC
This package is auto-updated.
Last update: 2024-09-08 07:14:41 UTC
README
用户操作(访问页面)的完整和舒适的日志,插入、更新、删除
安装
安装此扩展的首选方式是通过composer。
要安装,请运行
$ php composer.phar require rikcage/yii2-user-logs "*"
或添加
"rikcage/yii2-user-logs": "*"
到你的composer.json文件的require部分。
运行迁移以创建logs表(这意味着应用程序已经配置了数据库连接)
./yii migrate --migrationPath=@rikcage/user-logs/migrations
添加模块
将模块包含到配置文件中(高级应用程序使用backend/config/main.php,基本应用程序使用config/web.php和config/console)
'modules' => [ ... 'logs' => [ // you can create several 'logs', 'logs_admin', etc. sections // if you want another table different from '{{%logs}} or several tables 'class' => 'rikcage\user_logs\UserLogs', 'params' => [ 'userClass' => 'account\models\User', 'username' => 'user_name', 'userid' => 'user_id', //'log_table' => '{{%logs_admin}}', // if you want another table different from '{{%logs}}', default 'log_table' => '{{%logs}}' ], 'access_rules' => [ // Setting permissions for viewing logs (http://your_site/logs/logs) [ 'actions' => null, //for all 'allow' => true, 'roles' => ['@'], ], ], //'behaviors_params' => [ // additional settings of the behaviors () method for Logic Controller, // eg using access control extensions. // 'as AccessBehavior' => [ // 'class' => AccessBehavior::className(), // ], //], //'virtual_cron' => false, //default virtual_cron=true once a day deletes old logs for disable use virtual_cron=false //'var_name_last_delete' => 'logs_last_delete', // variable name the date of the last clean of the log, default var_name_last_delete=logs_last_delete 'logs_live' => '-100 day', // lifetime of log 'gitignore_list' => [ // ignored events of controllers and models. 'rikcage\user_logs\controllers\LogsController', ], ], ],
要禁用,使用虚拟_cron设置'virtual_cron' => false
控制器安装指南
将其添加到您的Controller中
use rikcage\user_logs\models\UserLog; ... public function beforeAction($action) { if (!parent::beforeAction($action)) { return false; } UserLog::initTable('logs'); // if you want another section with settings different from 'logs_admin' model $log = new UserLog; $log->actionlog('ACTION', $this); return true; }
模型安装指南
将其添加到您的Model中
use rikcage\user_logs\models\UserLog; ... public function behaviors() { ... //UserLog::initTable('logs_admin'); // if you want another section with settings different from 'logs' model return [ ... UserLog::className(), ]; }