lukmil lukmil - 11 days ago 4
PHP Question

how to reach login.php.. Object not found symfony3

Hello I want to reach my login.php code.. but i got firstly redirect to / (home)
error

I have one controller and its my code

/**
* @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,
));
}


I try to reach localhost:8000/login but still i got redirected to home.. what did i missed or what?

Answer

Ok, I got no responses, so how i fixed this.. I create new controller called ChampController.. And i put my code in different route.. all action with champs I made route ../champion/{champ} and then my login with champion didn't duplicate and now everything is working :)