2017 © Pedro Peláez
 

library yii2-ip-behavior

Yii2 Behavior that records User IP address on Updates/Inserts

image

ruskid/yii2-ip-behavior

Yii2 Behavior that records User IP address on Updates/Inserts

  • Saturday, November 7, 2015
  • by ruskid
  • Repository
  • 1 Watchers
  • 7 Stars
  • 1,114 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 1 Versions
  • 17 % Grown

The README.md

Yii2 Ip Behavior

Yii2 Behavior that records User IP address on Updates/Inserts, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require ruskid/yii2-ip-behavior "dev-master"

or add, (*4)

"ruskid/yii2-ip-behavior": "dev-master"

to the require section of your composer.json file., (*5)

Or

I wanted to test the composer xd. You can just copy paste IpBehavior.php to behaviors folder or any folder you like. (just don't forget to change the namespace)., (*6)

Usage

You can call it like this., (*7)

public function behaviors() {
        return [
            ...
            'ip' => [
                'class' => IpBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_ip', 'updated_ip'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_ip',
                ],
            ]
            ...
        ];
    }

Or like this. where value can be a string or an anonymous function that will return a string., (*8)

public function behaviors() {
        return [
            ...
            'ip' => [
                'class' => IpBehavior::className(),
                'createdIpAttribute' => 'created_ip',
                'updatedIpAttribute' => 'updated_ip',
                'value' => '127.0.0.1',
            ]
            ...
        ];
    }

Extras

this will set user's IP address to the attribute of the model., (*9)

$user->setIp('updated_ip');

The Versions

07/11 2015

dev-master

9999999-dev https://github.com/ruskid/yii2-ip-behavior

Yii2 Behavior that records User IP address on Updates/Inserts

  Sources   Download

BSD-3

The Requires

 

by Victor Demin

yii behavior ip