ユーザーが 1 つの属性を持っているかどうかをリダイレクトするために、symfony2 アプリケーションでログイン後にリダイレクトを実装しようとしています。プロジェクトの Handler フォルダー内にクラス AuthenticationSuccessHandler.php を作成しました。
名前空間 Me\MyBundle\Handler;
Symfony\Component\Security\Http\HttpUtils を使用します。
Symfony\Component\HttpFoundation\RedirectResponse を使用します。
Symfony\Component\HttpFoundation\Request を使用します。
Symfony\Component\Security\Core\Authentication\Token\TokenInterface を使用します。
Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler を使用します。
class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler {
public function __construct( HttpUtils $httpUtils, 配列 $options ) {
parent::__construct( $httpUtils, $options );
}
public function onAuthenticationSuccess( Request $request, TokenInterface $token ) {
$user = $token->getUser();
if($user->getProfile()!=1){
$url = 'fos_user_profile_edit';
}そうしないと{
$url = 'My_route';
}
return new RedirectResponse($this->router->generate($url));
}
}
しかし、ログインすると、次のエラーが表示されます。
Notice: 未定義のプロパティ: Me\MyBundle\Handler\AuthenticationSuccessHandler::$router in /var/www/MyBundle/src/Me/MyBundle/Handler/AuthenticationSuccessHandler.php 行 28
エラーは、「return new RedirectResponse($this->router->generate($url));」で発生しています。
私も私のサービスを持っています:
my_auth_success_handler:
クラス: Me\MyBundle\Handler\AuthenticationSuccessHandler
公開: false
引数: [ @security.http_utils, [] ]
security.yml の成功ハンドラー:
fos_facebook:
success_handler: my_auth_success_handler
何か案は?どうもありがとうございました。