11# Footprint
22
3- [ ![ Build Status] ( https://img.shields.io/travis/UseMuffin/Footprint/master.svg?style=flat-square )] ( https://travis-ci.org /UseMuffin/Footprint )
4- [ ![ Coverage] ( https://img.shields.io/codecov/c/github /UseMuffin/Footprint.svg ?style=flat-square )] ( https://codecov.io/github/UseMuffin/Footprint )
3+ [ ![ Build Status] ( https://img.shields.io/travis/UseMuffin/Footprint/master.svg?style=flat-square )] ( https://github.com /UseMuffin/Footprint/actions?query=workflow%3ACI+branch%3Amaster )
4+ [ ![ Coverage] ( https://img.shields.io/github/workflow/status /UseMuffin/Footprint/CI/master ?style=flat-square )] ( https://codecov.io/github/UseMuffin/Footprint )
55[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/muffin/footprint.svg?style=flat-square )] ( https://packagist.org/packages/muffin/footprint )
66[ ![ License] ( https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square )] ( LICENSE )
77
@@ -15,7 +15,7 @@ such as `user_id`, `created_by`, `company_id` similar to the core's `TimestampBe
1515
1616Using [ Composer] [ composer ] :
1717
18- ```
18+ ``` bash
1919composer require muffin/footprint
2020```
2121
@@ -25,32 +25,34 @@ You then need to load the plugin by running console command:
2525bin/cake plugin load Muffin/Footprint
2626```
2727
28- ## Usage
28+ The Footprint plugin must be loaded ** before** the [ Authentication] ( https://github.com/cakephp/authentication ) plugin,
29+ so you should move the
2930
30- ### Trait
31+ ``` php
32+ $this->addPlugin('Muffin/Footprint');
33+ ```
3134
32- First, you will need to include the ` Muffin\Footprint\Auth\FootprintAwareTrait `
33- to your ` AppController ` :
35+ statement above the
3436
3537``` php
36- use Muffin\Footprint\Auth\FootprintAwareTrait;
38+ $this->addPlugin('Authentication');
39+ ```
3740
38- class AppController extends Controller
39- {
40- use FootprintAwareTrait;
41+ in your ` Application::bootstrap() ` manually if required.
4142
42- // Specify the user model if required. Defaults to "Users".
43- $this->_userModel = 'YourPlugin.Members';
44- }
45- ```
43+ ## Usage
4644
47- This will attach the ` Muffin\Footprint\Event\FootprintListener ` to models
48- which will inject the currently logged in user's instance on ` Model.beforeSave `
49- and ` Model.beforeFind ` in the ` _footprint ` key of ` $options ` .
45+ ### Middleware
5046
51- Your controller needs to have either ` cakephp/authentication ` plugin's ` AuthenticationComponent `
52- or CakePHP core's deprecated ` AuthComponent ` loaded so that the user identity
53- can be fetched.
47+ Add the ` FootprintMiddleware ` to the middleware queue in your ` Application::middleware() `
48+ method:
49+
50+ ``` php
51+ $middleware->add('Muffin/Footprint.Footprint');
52+ ```
53+
54+ It must be added ** after** ` AuthenticationMiddleware ` to ensure that it can read
55+ the identify info after authentication is done.
5456
5557### Behavior
5658
@@ -67,7 +69,7 @@ You can customize that like so:
6769$this->addBehavior('Muffin/Footprint.Footprint', [
6870 'events' => [
6971 'Model.beforeSave' => [
70- 'user_id' => 'new',
72+ 'user_id' => 'new',
7173 'company_id' => 'new',
7274 'modified_by' => 'always'
7375 ]
@@ -83,16 +85,6 @@ fields when creating a record, on the `modified_by` field again when updating
8385the record and it will use the associated user record's company ` id ` in the
8486` company_id ` field when creating a record.
8587
86- ## Warning
87-
88- If you have the ` FootprintBehavior ` attached to a model do not load the model inside
89- ` Controller::initialize() ` method directly or indirectly. If you do so the
90- footprint (user entity) won't be set for the model and the behavior won't work
91- as expected. You can load your model in ` Controller::beforeFilter() ` if needed.
92-
93- This is because the ` FootprintListener ` which sets the user entity to the models
94- is attached after ` Controller::initialize() ` is run.
95-
9688## Patches & Features
9789
9890* Fork
@@ -114,4 +106,3 @@ Copyright (c) 2015-Present, [Use Muffin][muffin] and licensed under [The MIT Lic
114106[ composer ] :http://getcomposer.org
115107[ mit ] :http://www.opensource.org/licenses/mit-license.php
116108[ muffin ] :http://usemuffin.com
117- [ Ceeram/Blame ] :http://github.com/ceeram/blame
0 commit comments