嗨,大家好,我需要你們的幫助,是不是我對symfony的第一次登錄,但我真的不知道我做錯了這個時候,我收到此錯誤錯誤logincheck symfony3。*
Impossible to access an attribute ("title") on a boolean variable ("").
嘛問題是,當我嘗試登錄我不知道爲什麼去PostController中,這裏是我的代碼 Securyty.yml
安全: 提供商: 用戶: 實體:{類:的appbundle \實體\用戶屬性:電子郵件}
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(),
]);
}
}
是這最後一個是我的問題,當我嘗試登錄錯誤是原因去到singlePostAction,我不知道爲什麼,這個行動只是w如果用戶在首頁上點擊帖子標題
請您分享一下你的'front/homepage/_login.html.twig'嗎? –