UseMuffin / Footprint

CakePHP plugin to allow passing currently logged in user to model layer.
MIT License
95 stars 23 forks source link

integration with authentication plugin #59

Closed waspinator closed 5 years ago

waspinator commented 5 years ago

I'm trying to use this plugin with the official authentication plugin, but I'm doing something wrong. I tried following the suggestion in the readme by adding:

use Muffin\Footprint\Auth\FootprintAwareTrait;

class AppController extends Controller
{
    use FootprintAwareTrait {
        _setCurrentUser as _footprintSetCurrentUser;
    }

    protected function _setCurrentUser($user = null)
    {
        if (!$user) {
            $user = $this->request->getAttribute('identity');
        }

        return $this->_footprintSetCurrentUser($user);
    }
}

to my AppController, but I get a TypeError Argument 1 passed to Cake\ORM\Marshaller::one() must be of the type array, object given, called in /app/vendor/cakephp/cakephp/src/ORM/Table.php on line 2630

calling $user->toArray() doesn't work, with a Call to undefined method Authentication\Identity::toArray() error.

wrapping the [$user] object in an array resolves errors, but doesn't actually save created_by/modified_by fields in the database.

theogranero commented 5 years ago

Use $this->request->getAttribute('identity')->getOriginalData(); instead.