Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony][Symfony2]"errors" does not exist, Przesyłanie do szablonu listy błędów.
q3trm
post
Post #1





Grupa: Zarejestrowani
Postów: 83
Pomógł: 1
Dołączył: 26.02.2013

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


Nie mogę dojść gdzie popełniam błąd (IMG:style_emoticons/default/dry.gif) , to mój pierwszy formularz w Symfony przykład z cookbook.


  1. public function contactAction()
  2. {
  3. $enquiry = new Enquiry();
  4.  
  5. $form = $this->createForm(new EnquiryType(), $enquiry);
  6.  
  7. $request= $this ->getRequest();
  8.  
  9. if ($request == 'POST') {
  10. $form ->bind($request);
  11.  
  12. $validator = $this->get('validator');
  13. $errors = $validator->validate($enquiry);
  14.  
  15. if ($form ->isValid()) {
  16.  
  17. if (count($errors) > 0) {
  18. return $this ->render('MultimediaBlogBundle:Default:contact.html.twig', array(
  19. 'errors' => $errors ));
  20. }
  21. }
  22. return $this -> redirect($this->generateUrl('multimedia_contact'));
  23. }
  24. return $this ->render('MultimediaBlogBundle:Default:contact.html.twig', array(
  25. 'form' => $form->createView()));
  26. }
  27.  
  28.  


  1. <ul>
  2. {% for error in errors %}
  3. <li>{{ error.message }}</li>
  4. {% endfor %}
  5. </ul>


Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
q3trm
post
Post #2





Grupa: Zarejestrowani
Postów: 83
Pomógł: 1
Dołączył: 26.02.2013

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


Znalazłem pierwszy błąd

  1. if ($request == 'POST')


  1. if ($request -> getMethod() == 'POST')


teraz przynajmniej instrukcja się wykonuje (IMG:style_emoticons/default/snitch.gif)


EDIT//
  1. public function contactAction()
  2. {
  3. $enquiry = new Enquiry();
  4.  
  5. $form = $this->createForm(new EnquiryType(), $enquiry);
  6.  
  7. $request= $this ->getRequest();
  8.  
  9. if($request-> getMethod() == 'POST') {
  10. $form ->bind($request);
  11.  
  12. $validator = $this->get('validator');
  13. $errors = $validator->validate($enquiry);
  14.  
  15.  
  16. if (count($errors) > 0) {
  17. return $this ->render('MultimediaBlogBundle:Default:contact.html.twig', array(
  18. 'errors' => $errors,
  19. 'form' =>$form ->createView(),
  20. ));
  21. }
  22.  
  23. return $this -> redirect($this->generateUrl('multimedia_contact'));
  24.  
  25. }
  26. return $this ->render('MultimediaBlogBundle:Default:contact.html.twig', array(
  27. 'form' => $form->createView()));
  28.  
  29. }
  30.  


Wszystko działa poprawnie bez użycia metody IsValid().

Ten post edytował q3trm 29.05.2013, 12:49:53
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 27.12.2025 - 13:51