定制 budipratama/yii2-ipbehaviors 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

budipratama/yii2-ipbehaviors

Composer 安装命令:

composer require budipratama/yii2-ipbehaviors

包简介

Ip Behaviors

README 文档

README

Ip Behaviors

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist budipratama/yii2-ipbehaviors "@dev"

or add

"budipratama/yii2-ipbehaviors": "@dev"

to the require section of your composer.json file.

Usage

IpBehaviors automatically fills the specified attributes with the current ip user login. To use IpBehaviors, insert the following code your ActiveRecord class:

use budipratama\behaviors\IpBehaviors;

 public function behaviors()
 {
     return [
           [
               'class' => IpBehaviors::class
           ],
     ];
 }

By default, IpBehaviors will fill the first_ip and last_ip attributes with the current ip user when created row the associated AR object is being inserted. it will fill the last_ip attribute with the ip when the AR object is being updated. The ip value is obtained by Yii::$app->request->userIp. Because attribute values will be set automatically by this behavior, they are usually not user input and should therefore not be validated, i.e. first_ip and last_ip should not appear in the rules() method of the model. For the above implementation to work with MySQL database, please declare the columns(first_ip, last_ip) as varchar(15). If your attribute names are different, you may configure the $createdAtAttribute, $updatedAtAttribute and $value properties like the following:

 public function behaviors()
 {
     return [
           [
               'class' => IpBehaviors::class,
               'createdAtAttribute' => 'first_ip',
               'updatedAtAttribute' => 'last_ip',
               'value' => function(){
                   return \Yii::$app->request->userIp;
               }
           ],
     ];
 } 

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固