大家好我需要你的帮助,这不是我第一次登录symfony但是我真的不知道这次我做错了什么,我收到了这个错误
Impossible to access an attribute ("title") on a boolean variable ("").
问题是当我尝试登录时我不知道为什么要去PostController,这是我的代码 Securyty.yml
安全性: 供应商: 用户: entity:{class:AppBundle \ Entity \ User,property:email}
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
frontend:
pattern: ^/*
provider: users
anonymous: ~
form_login:
login_path: user_login
check_path: user_login_check
logout:
path: user_logout
remember_me:
secret: 123
lifetime: 604800 # 604.800 = 3.600 * 24 * 7 = 1 week
access_control:
- { path: ^/*, roles: IS_AUTHENTICATED_ANONYMOUSLY }
encoders:
AppBundle\Entity\User: bcrypt
role_hierarchy:
ROLE_ADMIN: [ROLE_USER]
我的控制器
前
class FrontController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$featured=$em->getRepository('AppBundle:Post')->findBylimit(3);
$list_post=$em->getRepository('AppBundle:Post')->findAll();
return $this->render('front/homepage/index.html.twig',[
'featureds'=>$featured,
'list'=>$list_post,
]);
}
}
class SecurityController extends Controller
{
/**
* @Route("/login", name="user_login")
*/
public function loginAction()
{
$authUtils = $this->get('security.authentication_utils');
return $this->render('front/homepage/_login.html.twig', array(
'last_username' => $authUtils->getLastUsername(),
'error' => $authUtils->getLastAuthenticationError(),
));
}
/**
* @Route("/login_check", name="user_login_check")
*/
public function loginCheckAction()
{
}
/**
* @Route("/logout", name="user_logout")
*/
public function logoutAction()
{
}
public function boxloginAction()
{
$authUtils = $this->get('security.authentication_utils');
return $this->render('front/homepage/_login.html.twig', array(
'last_username' => $authUtils->getLastUsername(),
'error' => $authUtils->getLastAuthenticationError(),
));
}
class PostController extends Controller
{
/**
*@Route("/{slug}/",name="view_post")
*
*/
public function singlePostAction(Request $request,$slug){
$em = $this->getDoctrine()->getManager();
$id=$request->get('id');
$single_post=$em->getRepository('AppBundle:Post')->findByTitle($slug,$id);
$coments=$em->getRepository('AppBundle:Post_comment')->findByPost($single_post);
if($single_post){
$single_post->setViews($single_post->getViews()+1);
$em->flush($single_post);
}
return $this->render('front/post/_single.html.twig', [
'single_post'=>$single_post,
'comments'=>$coments,
]);
}
public function postCommentAction(Request $request){
$comment= new Post_comment();
$form = $this->createForm(Post_commentType::class, $comment);
$form->handleRequest($request);
if($form->isSubmitted()){
}
return $this->render('front/post/_comment.html.twig', [
'form'=>$form->createView(),
]);
}
}
/**
*@Route("/{slug}/",name="view_post")
*
*/
public function singlePostAction(Request $request,$slug){
$em = $this->getDoctrine()->getManager();
$id=$request->get('id');
$single_post=$em->getRepository('AppBundle:Post')->findByTitle($slug,$id);
$coments=$em->getRepository('AppBundle:Post_comment')->findByPost($single_post);
if($single_post){
$single_post->setViews($single_post->getViews()+1);
$em->flush($single_post);
}
return $this->render('front/post/_single.html.twig', [
'single_post'=>$single_post,
'comments'=>$coments,
]);
}
public function postCommentAction(Request $request){
$comment= new Post_comment();
$form = $this->createForm(Post_commentType::class, $comment);
$form->handleRequest($request);
if($form->isSubmitted()){
}
return $this->render('front/post/_comment.html.twig', [
'form'=>$form->createView(),
]);
}
这是最后一个是我的问题,当我尝试登录错误是因为转到singlePostAction而我不知道为什么,这个动作只是当用户在主页上标题帖子时
答案 0 :(得分:1)
因为/{slug}/
正在捕捉其他路线!