如何到达login.php ..找不到对象symfony3

时间:2016-11-24 09:47:47

标签: php symfony-3.1

您好我想要达到我的login.php代码..但我首先重定向到/(主页) error

我有一个控制器及其代码

/**
     * @Route("/{champ}", name="home", defaults={"champ" = 1})
     */
    public function mainAction(Request $request,champion $champ)
    {

        $user = $this->getUser();
        $form = $this->createForm(UserType::class, $user);
        $champi = new champion();;
        $form2 = $this->createForm(ChampionType::class, $champi);
        $form3 = $this->createForm(ChampionsType::class, $champ);
        $form4 = $this->createForm(ChampionTypes::class, $champ);
        $form2->handleRequest($request);
        $form->handleRequest($request);
        $form3->handleRequest($request);
        $form4->handleRequest($request);
        if ($form->isValid() && $form->isSubmitted()) {
            $password = $this->get('security.password_encoder')
                ->encodePassword($user, $user->getPlainPassword());
            $user->setPassword($password);
            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($user);
            $em->flush();
            $this->addFlash("success", '');
        }
        if ($form2->isValid() && $form2->isSubmitted()) {
            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($champi);
            $em->flush();
            $this->addFlash("success", '');
        }
        if ($form3->isValid() && $form3->isSubmitted()) {
            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($champ);
            $em->flush();
            $this->addFlash("success", '');
        }
        if ($form4->isValid() && $form4->isSubmitted()) {
            $em = $this->getDoctrine()->getEntityManager();
            $em->remove($champ);
            $em->flush();
            $this->addFlash("success", '');
        }

        $champ = $this->getDoctrine()
            ->getRepository('AppBundle:champion')
            ->findAll();
        $champs = $this->getDoctrine()
            ->getRepository('AppBundle:champion')
            ->findAll();

        return $this->render('AppBundle:uzduotis:index.html.twig', [
            'form' => $form->createView(),
            'form2' => $form2->createView(),
            'form3' => $form3->createView(),
            'form4' => $form4->createView(),
            'user' => $user,
            'champions' => $champ
        ]);
    }


    /**
     * @Route("/login", name="authentication_login")
     *  @Method({"GET","POST"})
     */
    public function loginActionAction(Request $request)
    {
        $authenticationUtils = $this->get('security.authentication_utils');

        // get the login error if there is one
        $error = $authenticationUtils->getLastAuthenticationError();

        // last username entered by the user
        $lastUsername = $authenticationUtils->getLastUsername();

        return $this->render('AppBundle:uzduotis:login.html.twig', array(
            'last_username' => $lastUsername,
            'error' => $error,
        ));
    } 

我尝试访问localhost:8000 /登录但仍然被重定向到家..我错过了什么或什么?

1 个答案:

答案 0 :(得分:0)

好吧,我没有得到任何回复,所以我如何解决这个问题..我创建了一个名为ChampController的新控制器..而且我把我的代码放在不同的路线上...所有行动都与冠军我做了路线../champion/{champ}然后我与冠军的登录没有重复,现在一切正常:)