dev-master
9999999-dev http://github.com/thefredfox/cakephp-ip-behaviorIpBehavior plugin for CakePHP
MIT
The Requires
- php >=5.4.16
- cakephp/cakephp ~3.0
The Development Requires
by TheFRedFox
database php cakephp behavior ip
IpBehavior plugin for CakePHP
An Ip Behavior for the Database Framework of CakePHP, which fills a specified field of an entity with the current client ip taken from the current request., (*1)
This plugin should work lovely with the IpType plugin., (*2)
You can install this plugin into your CakePHP application using composer., (*3)
The recommended way to install composer packages is:, (*4)
``` php composer require thefredfox/cakephp-ip-behavior, (*5)
After that you have to load the plugin in your application's bootstrap file and map the type for the database as follows: ``` php Plugin::load('IpBehavior', ['bootstrap' => true]);
In the Table class itself you have to add this behavior:, (*6)
``` php // in your Entity Table class (eg. UsersTable), (*7)
public function initialize(array $config) { //... $this->addBehavior('IpBehavior.Ip'); //... }, (*8)
The default is, that the behavior will use the field named 'ip', but you can change the configurations like this: ``` php // in your Entity Table class (eg. UsersTable) public function initialize(array $config) { //... $this->addBehavior('IpBehavior.Ip', ['fields' => ['other_ip_field']); //... }
and if you want that the ip should always be stored:, (*9)
``` php // in your Entity Table class (eg. UsersTable), (*10)
public function initialize(array $config) { //... $this->addBehavior('IpBehavior.Ip', ['fields' => ['ip' => 'always']); // respectively $this->addBehavior('IpBehavior.Ip', ['fields' => ['other_ip_field' => 'always']); //... }, (*11)
In that way you can store the creators and the modifiers ip: ``` php // in your Entity Table class (eg. UsersTable) public function initialize(array $config) { //... $this->addBehavior('IpBehavior.Ip', ['fields' => ['ip', 'other_ip_field' => 'always']); //... }
The 'new' configuration is default and you don't need to explicitly set it., (*12)
IpBehavior plugin for CakePHP
MIT
database php cakephp behavior ip