PHP code example of myzero1 / yii2-log

1. Go to this page and download the library: Download myzero1/yii2-log library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

myzero1 / yii2-log example snippets


return [
    ......
    'bootstrap' => [
        ......
        'z1log',
        ......
    ],
    'modules' => [
        ......
        'z1log' => [
            'class' => '\myzero1\log\Module',    
            'params' => [
                'urlManager' => [
                    'rules' => [
                        // 'rate/area/index' => 'rate/jf-core-area/index',
                    ],
                ],
                'remarksFieldsKey' => [
                    'remark', // default filed
                    // 'r1', // custom field, can add it by yourself
                ],
                'userInfo' => [
                    'id' => function(){
                        if(\Yii::$app->user->isGuest){
                            $id = 0;
                        } else {
                            $id = \Yii::$app->user->identity->id;
                        }

                        return $id;
                    },
                    'name' => function(){
                        if(\Yii::$app->user->isGuest){
                            $name = 'system';
                        } else {
                            $name = \Yii::$app->user->identity->username;
                        }
                        
                        return $name;
                    }
                ],
                'template' => [
                    'user2/create' => [
                        'model' => 'all', // text,screenshot,all
                        'addToTable' => 'user', // for creating
                        'text' => function(){
                            return '添加用户'; 
                        },
                        'screenshot' => 'user2/update', // The template of screenshot
                        'obj' => [
                            'label' => '.field-user2-username .control-label',
                            'value' => '#user2-username',
                        ],
                        'remarks' => [// the items must be Closure
                            'remark' => function(){
                                return sprintf('Create it at %s.', date('Y-m-d H:i:s'));
                            },
                            // 'r1' => function(){return 'r1'.time();},
                        ],
                    ],
                    'user2/update' => [
                        'model' => 'all', // text,screenshot,all
                        'text' => function(){
                            return '修改用户'; 
                        },
                        'screenshot' => 'user2/update', // The template of screenshot
                        'obj' => [
                            'label' => '.field-user2-username .control-label',
                            'value' => '#user2-username',
                        ],
                        'remarks' => [// the items must be Closure
                            'remark' => function(){
                                return sprintf('Update it at %s.', date('Y-m-d H:i:s'));
                            },
                        ],
                    ],
                    'user2/delete' => [
                        'model' => 'all', // text,screenshot,all
                        'text' => function(){
                            return '删除用户'; 
                        },
                        'screenshot' => 'user2/update', // The template of screenshot
                        'obj' => [
                            'label' => '.field-user2-username .control-label',
                            'value' => '#user2-username',
                        ],
                        'remarks' => [// the items must be Closure
                            'remark' => function(){
                                return sprintf('Delete it at %s.', date('Y-m-d H:i:s'));
                            },
                        ],
                    ],
                ],
            ],
        ],
        ......
    ],
    ......
];


\myzero1\log\components\export\Export::z1logAdd('all', 'user2/update', ['id'=>$model->id], 'create user', sprintf('username:%s', $model->username), ['remark'=>'this is a remark']);

 


    /**
     * Creates a new User2 model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new User2();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            
            \myzero1\log\components\export\Export::z1logAdd('all', 'user2/update', ['id'=>$model->id], 'create user', sprintf('username:%s', $model->username), '');

            Yii::$app->getSession()->setFlash('success', '添加成功');
            return \myzero1\adminlteiframe\helpers\Tool::redirectParent(['index']);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

cmd
    php yii migrate --migrationPath=@vendor/myzero1/yii2-log/src/migrations