Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony][Doctrine] Formularze, przechowanie zawartości pola "entity"
rcetra
post
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 16.12.2011

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


Jest sobie kod, który ma za zadanie wziąc dane z formularza przy wywołaniu POST i zapisać do sesji.
Kiedy już ma zapisane dane, ma je wykorzystać jako dane domyślne dla formularza.
Zadanie banalne, ale próbuję żeby się nie napisać zbyt wiele i nie tworzyć od nowa obiektów, po prostu te dane zserializować.
Niestety, pojawia się błąd "Entities passed to the choice field must be managed 500 Internal Server Error - FormException".
Czy ktoś zna jakiś sposób na zgrabne przeniesienie tych danych np. do następnej strony?

Fragment z kontrolera z formatką:
  1. $session = $this->get('session');
  2. $session->start();
  3. $defaultData = $session->get($this->name_session_data, array());
  4. if(is_string($defaultData)){
  5. $defaultData = unserialize($defaultData);
  6. }
  7. // Formatka do filtrowania
  8. $filter_form = $this->createFormBuilder($defaultData)
  9. ->add('lang', 'entity', array(
  10. 'class' => 'BDKTranslatorBundle:TranslatorLang',
  11. 'multiple' => true,
  12. 'expanded' => true,
  13. 'label' => 'Język',
  14. 'required' => false
  15. ))
  16. ->add('app', 'entity', array(
  17. 'class' => 'BDKTranslatorBundle:TranslatorApp',
  18. 'multiple' => true,
  19. 'expanded' => false,
  20. 'label' => 'Aplikacja',
  21. 'required' => false
  22. ))
  23. ->add('name', 'text', array(
  24. 'label' => 'Nazwa tekstu',
  25. 'required' => false
  26. ))
  27. ->add('desc', 'text', array(
  28. 'label' => 'Opis tłumaczenia tekstu',
  29. 'required' => false
  30. ))
  31. ->add('body', 'text', array(
  32. 'label' => 'Tekst tłumaczenia tekstu',
  33. 'required' => false
  34. ))
  35. ->add('without_translation', 'checkbox', array(
  36. 'label' => 'Bez tłumaczenia',
  37. 'required' => false,
  38. ))
  39. ->getForm();
  40.  
  41. if ($request->getMethod() == 'POST') {
  42. $filter_form->bindRequest($request);
  43. $filter_data = $filter_form->getData();
  44. $session->set($this->name_session_data, serialize($filter_data));
  45. $session->save();
  46. }


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: 23.08.2025 - 04:41