OctoberCMS user.register 事件未触发?
OctoberCMS user.register event not firing?
我正在收听 rainlab.user.register 事件,但似乎什么也没发生。我想获取已注册的 user_id 并对其进行处理,例如将其保存在另一个数据库中。
我正在使用 jwtauth 插件来注册用户。用户也可以通过 sociallogin 插件注册。我正在用邮递员测试用户注册,注册请求成功但事件似乎没有触发。我怎样才能做到这一点。这是我插件的 boot() 方法 中的代码。
Event::listen('eloquent.created:RainLab\User\Models\User', function($user) {
$position= Position::where('title','staff')->first();
$assign_position = new RankUser;
$assign_position->user_id = $user->id;
$assign_position->position_id= $position->id;
$assign_position->save();
//Nothing being saved in DB after successful user registration.
});
我也试过这个:
Event::listen('rainlab.user.register', function($user) {
$position = Position::where('title','staff')->first();
$assign_position = new Position;
$assign_position->user_id = $user->id;
$assign_position->position_id= $position->id;
$assign_position->save();
});
但还是没有任何反应。
可能做错了什么。请一些指导。
有些事件是插件独有的,例如
Event::listen('rainlab.user.register', function($user) { //code });
这个 rainlab.user.registe
只会在你 registering user
和 there controller only
时触发
所以如果你 add user out of its scope this event will not fire
我怀疑 jwtauth plugin
是 creating user by its own
直接使用 RainLab\User\Models\User
模型,因此不会触发此事件。
但是在这种情况下应该触发你的 eloquent.created
事件,但我发现你 event string
和代码库
中有些问题
static::$dispatcher->{$method}("eloquent.{$event}: ".static::class, $this);
//there is one space, my guess is this is causing ^ you problem
所以尝试将 event string
与 space 一起使用,就像打击
Event::listen('eloquent.created: RainLab\User\Models\User', function($user)
// try to add single space here ^ it should work
{
//code
});
如果不成功请评论。
我正在收听 rainlab.user.register 事件,但似乎什么也没发生。我想获取已注册的 user_id 并对其进行处理,例如将其保存在另一个数据库中。 我正在使用 jwtauth 插件来注册用户。用户也可以通过 sociallogin 插件注册。我正在用邮递员测试用户注册,注册请求成功但事件似乎没有触发。我怎样才能做到这一点。这是我插件的 boot() 方法 中的代码。
Event::listen('eloquent.created:RainLab\User\Models\User', function($user) {
$position= Position::where('title','staff')->first();
$assign_position = new RankUser;
$assign_position->user_id = $user->id;
$assign_position->position_id= $position->id;
$assign_position->save();
//Nothing being saved in DB after successful user registration.
});
我也试过这个:
Event::listen('rainlab.user.register', function($user) {
$position = Position::where('title','staff')->first();
$assign_position = new Position;
$assign_position->user_id = $user->id;
$assign_position->position_id= $position->id;
$assign_position->save();
});
但还是没有任何反应。
可能做错了什么。请一些指导。
有些事件是插件独有的,例如
Event::listen('rainlab.user.register', function($user) { //code });
这个 rainlab.user.registe
只会在你 registering user
和 there controller only
所以如果你 add user out of its scope this event will not fire
我怀疑 jwtauth plugin
是 creating user by its own
直接使用 RainLab\User\Models\User
模型,因此不会触发此事件。
但是在这种情况下应该触发你的 eloquent.created
事件,但我发现你 event string
和代码库
static::$dispatcher->{$method}("eloquent.{$event}: ".static::class, $this);
//there is one space, my guess is this is causing ^ you problem
所以尝试将 event string
与 space 一起使用,就像打击
Event::listen('eloquent.created: RainLab\User\Models\User', function($user)
// try to add single space here ^ it should work
{
//code
});
如果不成功请评论。