Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [SF2][Symfony][Symfony2]Attempted to call method "redirectToRoute"
kosmos
post 29.03.2015, 12:22:05
Post #1





Grupa: Zarejestrowani
Postów: 367
Pomógł: 17
Dołączył: 4.03.2008

Ostrzeżenie: (0%)
-----


Witam
Mam problem z przekierowaniem do innej strony:

  1. namespace Acme\PageBundle\Controller;
  2.  
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Acme\PageBundle\Entity\Message;
  5. use Symfony\Component\HttpFoundation\Request;
  6. class DefaultController extends Controller
  7. {
  8. public function contactAction(Request $request)
  9. {
  10. $message = new Message();
  11. $message->setName('');
  12. $message->setSurname('');
  13.  
  14. $form = $this->createFormBuilder($message)
  15. ->add('name','text')
  16. ->add('Wyślij zapytanie','submit')
  17. ->getForm();
  18.  
  19. $form->handleRequest($request);
  20.  
  21. if ($form->isValid()) {
  22. // perform some action...
  23. return $this->redirectToRoute('acme_task_success');
  24. }
  25.  
  26. return $this->render('AcmePageBundle:Default:contact.html.php', array(
  27. 'form' => $form->createView(),
  28. ));
  29. }
  30. }


Po wywołaniu submita pojawia się problem z wywołaniem funkcji redirectToRoute nie wiem dlaczego

Attempted to call method "redirectToRoute" on class "Acme\PageBundle\Controller\DefaultController" in C:\xampp\htdocs\symfony\src\Acme\PageBundle\Controller\DefaultController.php line 84.


EMERGENCY - Call to undefined method Acme\PageBundle\Controller\DefaultController::redirectToRoute()
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\UndefinedMethodException: "Attempted to call method "redirectToRoute" on class "Acme\PageBundle\Controller\DefaultController" in C:\xampp\htdocs\symfony\src\Acme\PageBundle\Controller\DefaultController.php line 84." at C:\xampp\htdocs\symfony\src\Acme\PageBundle\Controller\DefaultController.php line 84


Pomożecie?
Go to the top of the page
+Quote Post
ohm
post 29.03.2015, 12:43:20
Post #2





Grupa: Zarejestrowani
Postów: 619
Pomógł: 143
Dołączył: 22.12.2010

Ostrzeżenie: (0%)
-----


Jaka wersja symfony?

Cytat
The redirectToRoute() method was added in Symfony 2.6. Previously (and still now), you could use redirect() and generateUrl() together for this (see the example above).
Go to the top of the page
+Quote Post
kosmos
post 29.03.2015, 14:50:10
Post #3





Grupa: Zarejestrowani
Postów: 367
Pomógł: 17
Dołączył: 4.03.2008

Ostrzeżenie: (0%)
-----


"symfony/symfony": "2.5.*",

dzięki za info
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 27.04.2024 - 14:34