dev-master
9999999-dev https://github.com/ruskid/yii2-ip-behaviorYii2 Behavior that records User IP address on Updates/Inserts
BSD-3
The Requires
by Victor Demin
yii behavior ip
Yii2 Behavior that records User IP address on Updates/Inserts
Yii2 Behavior that records User IP address on Updates/Inserts, (*1)
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)
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)
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', ] ... ]; }
this will set user's IP address to the attribute of the model., (*9)
$user->setIp('updated_ip');
Yii2 Behavior that records User IP address on Updates/Inserts
BSD-3
yii behavior ip