You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This plugin allows you to pass the currently logged in user to the model layer of a CakePHP 3
9
-
application.
8
+
This plugin allows you to pass the currently logged in user info to the model layer
9
+
of a CakePHP application.
10
10
11
-
It comes bundled with the `FootprintBehavior` to allow you control over columns such as `user_id`,
12
-
`created_by`, `company_id`just like the core's `TimestampBehavior`.
11
+
It comes bundled with the `FootprintBehavior` to allow you control over columns
12
+
such as `user_id`, `created_by`, `company_id`similar to the core's `TimestampBehavior`.
13
13
14
14
## Install
15
15
16
16
Using [Composer][composer]:
17
17
18
18
```
19
19
composer require muffin/footprint
20
-
21
20
```
22
21
23
22
You then need to load the plugin by running console command:
24
23
25
24
```bash
26
-
bin/cake plugin load Muffin/Footprint
25
+
bin/cake plugin load Muffin/Footprint
27
26
```
28
27
29
28
## Usage
30
29
31
30
### Trait
32
31
33
-
First, you will need to include the `Muffin\Footprint\Auth\FootprintAwareTrait` to your `AppController`:
32
+
First, you will need to include the `Muffin\Footprint\Auth\FootprintAwareTrait`
33
+
to your `AppController`:
34
34
35
35
```php
36
36
use Muffin\Footprint\Auth\FootprintAwareTrait;
37
37
38
38
class AppController extends Controller
39
39
{
40
40
use FootprintAwareTrait;
41
-
}
42
-
```
43
-
44
-
This will attach the `Muffin\Footprint\Event\FootprintListener` to models
45
-
which will inject the currently logged in user's instance on `Model.beforeSave`
46
-
and `Model.beforeFind` in the `_footprint` key of `$options`.
47
-
48
-
The user record provided by `AuthComponent` is converted to `User` entity before
49
-
passing to models. If your `AuthComponent` is configured to use a non-default
50
-
users table you must set the `$_userModel` property of the trait to same table:
51
-
52
-
```php
53
-
public function initialize()
54
-
{
55
-
parent::initialize();
56
41
57
42
// Specify the user model if required. Defaults to "Users".
58
43
$this->_userModel = 'YourPlugin.Members';
59
-
60
-
$this->loadComponent('Auth', [
61
-
'authenticate' => [
62
-
'Form' => [
63
-
'userModel' => $this->_userModel, // Use same model for AuthComponent
64
-
],
65
-
],
66
-
]);
67
44
}
68
45
```
69
46
70
-
#### Using Footprint with cakephp/authentication
71
-
72
-
If you are using the `cakephp/authentication` plugin instead of the `AuthComponent`, you will need to update your controller to tell Footprint where to find the identity. To do so, update the trait declaration and overwride `_setCurrentUser` to get the identity from the request:
73
-
74
-
```php
75
-
use Muffin\Footprint\Auth\FootprintAwareTrait;
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`.
0 commit comments