thefredfox / cakephp-ip-behavior
IpBehavior plugin for CakePHP
Installs: 117
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=5.4.16
- cakephp/cakephp: ~3.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-10-26 00:14:07 UTC
README
Description
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.
This plugin should work lovely with the IpType plugin.
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require thefredfox/cakephp-ip-behavior
After that you have to load the plugin in your application's bootstrap file and map the type for the database as follows:
Plugin::load('IpBehavior', ['bootstrap' => true]);
In the Table class itself you have to add this behavior:
// in your Entity Table class (eg. UsersTable) public function initialize(array $config) { //... $this->addBehavior('IpBehavior.Ip'); //... }
The default is, that the behavior will use the field named 'ip', but you can change the configurations like this:
// 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:
// in your Entity Table class (eg. UsersTable) public function initialize(array $config) { //... $this->addBehavior('IpBehavior.Ip', ['fields' => ['ip' => 'always']); // respectively $this->addBehavior('IpBehavior.Ip', ['fields' => ['other_ip_field' => 'always']); //... }
In that way you can store the creators and the modifiers ip:
// 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.