我正在尝试设置我的安全性,因此它在登录后重定向回引用。
例如,我正在打开/个人资料/ {slug}
这是我的ProfileController
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class ProfileController extends Controller
{
public function indexAction(Request $request, $slug)
{
$authChecker = $this->get('security.authorization_checker');
if(!$authChecker->isGranted('ROLE_USER')) {
return $this->redirect($this->generateUrl('fos_user_security_login'));
}
$userManager = $this->container->get('fos_user.user_manager');
$user = $userManager->findUserByUsername($slug);
if(!$user) {
throw $this->createNotFoundException('Пользователь не найден');
}
return $this->render('AppBundle::profile.html.twig', array('user' => $user));
}
}
如果用户未登录,则控制器会重定向到登录路由。
用户登录后,会被重定向到主页。我想把它改成referer。
这是我的security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
login_path: /account/login
check_path: /account/login-check
use_referer: true
logout:
path: /account/logout
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
如您所见,我在那里添加了use_referer:true,但它无效。
那我该怎么做?