所以,我正在尝试用 Laravel 4.1 实现 Sentry 2。我正在使用这个资源
https://github.com/rydurham/L4withSentry
一切正常,但现在我想在用户注册时自动将用户分配给一个组。
来自 Sentry 2 Docs,
// Find the group using the group id
$adminGroup = Sentry::findGroupById(5);
// Assign the group to the user
$user->addGroup($adminGroup);
应该管用。所以我将这行代码添加到 Authority\Repo\User\SentryUser.php
现在代码看起来像
try {
//Attempt to register the user.
$user = $this->sentry->register(array(
'username' => e($data['username']),
'email' => e($data['email']),
'password' => e($data['password'])
));
// Find the group using the group id
$adminGroup = Sentry::findGroupById(5);
// Assign the group to the user
$user->addGroup($adminGroup);
//success!
$result['success'] = true;
$result['message'] = trans('users.created');
$result['mailData']['activationCode'] = $user->GetActivationCode();
$result['mailData']['userId'] = $user->getId();
$result['mailData']['email'] = e($data['email']);
}
但这会引发错误
Non-static method Cartalyst\Sentry\Sentry::findGroupById() should not be called statically, assuming $this from incompatible context
谁能阐明并告诉我我做错了什么?提前致谢