Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony2][Symfony]Entity not found, Nie można odnaleźć entity
Crash89
post
Post #1





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

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


Witam, borykam się z takim problem, otóż tworzę akcję kontrollera rozbitą na dwa kroki.
O ile w pierwszym kroku wszystko działa o tyle w drugim mam taki błąd, przy wejściu do drugiego kroku.

  1. AppBundle\Entity\GroupWords object not found.
  2. 404 Not Found - NotFoundHttpException


Oto kod tych akcji:

  1. /**
  2.   * Creates a new GroupWords entity.
  3.   *
  4.   * @Route("/new", name="groupwords_new")
  5.   * @Method({"GET", "POST"})
  6.   */
  7. public function newAction(Request $request)
  8. {
  9. $groupWord = new GroupWords();
  10. $form = $this->createForm('AppBundle\Form\GroupWordsType', $groupWord);
  11. $form->handleRequest($request);
  12.  
  13. if ($form->isSubmitted() && $form->isValid()) {
  14. //$em = $this->getDoctrine()->getManager();
  15. // $em->persist($groupWord);
  16. // $em->fluvar_dump('saafa');
  17.  
  18.  
  19. return $this->redirectToRoute('groupwords_new_step2', array('groupWord' => $groupWord));
  20. }
  21.  
  22. return $this->render('groupwords/new.html.twig', array(
  23. 'groupWord' => $groupWord,
  24. 'form' => $form->createView(),
  25. ));
  26. }
  27. /**
  28.  * @Route("/new_step2/{groupWord}", name="groupwords_new_step2")
  29.  * @Method({"GET","POST"})
  30.  * @param Request $request
  31.  *
  32.  *
  33.  */
  34. public function newStep2Action(Request $request, GroupWords $groupWord){
  35. $form = $this->createForm('AppBundle\Form\GroupWordsStep2Type', $groupWord);
  36. $form->handleRequest($request);
  37.  
  38. if ($form->isSubmitted() && $form->isValid()) {
  39. $em = $this->getDoctrine()->getManager();
  40. $em->persist($groupWord);
  41. $em->flush();
  42.  
  43. return $this->redirectToRoute('groupwords_show', array('id' => $groupWord->getId()));
  44. }
  45. return $this->render('groupwords/newStep2.html.twig', array(
  46. 'groupWord' => $groupWord,
  47. 'form' => $form->createView(),
  48. ));
  49.  
  50. }



Próbowałem to poustawiać przez @ParamConverter ale za wiele to nie zmieniło.

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





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

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


Jest sens bo każde słówko w jakimkolwiek języku może dodawać użytkownik.
Tworzę stronę gdzie się dodaje słówka z różnych języków.


Miałem juz okazję pracować z Craue i ten sposób przekazania parametru opcji działał.

Poniżej umieszczę kod:

  1.  
  2. namespace AppBundle\Form;
  3.  
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Doctrine\ORM\EntityRepository;
  7.  
  8. class CreateGroupWordsForm extends AbstractType {
  9.  
  10. //put your code here
  11.  
  12. public function buildForm(FormBuilderInterface $builder, array $options) {
  13. if (!empty($options['language'])) {
  14. $language = $options['language'];
  15. }
  16. switch ($options['flow_step']) {
  17. case 1:
  18. $builder
  19. ->add('name')
  20. ->add('language_1')
  21. ->add('language_2')
  22. ->add('category')
  23. ->add('user')
  24. ;
  25. break;
  26. case 2:
  27. // This form type is not defined in the example.
  28. $builder
  29. ->add('words', null, array('query_builder' => function (EntityRepository $er) use ($language) {
  30. return $er->createQueryBuilder('u')
  31. ->where('u.language = :language')
  32. ->steParameter(':language',$language);
  33. }));
  34. break;
  35. }
  36. }
  37.  
  38.  
  39.  
  40. public function configureOptions( OptionsResolver $resolver ) {
  41. $resolver->setDefaults( array(
  42. 'data_class' => 'AppBundle\Entity\GroupWords',
  43. 'language' => null
  44.  
  45. ) );
  46. }
  47.  
  48.  
  49. public function getBlockPrefix() {
  50. return 'createVehicle';
  51. }
  52.  
  53. public function getName() {
  54. return 'GroupWords';
  55. }
  56.  
  57. }
  58.  
  59.  
  60. namespace AppBundle\Form;
  61.  
  62. use Craue\FormFlowBundle\Form\FormFlow;
  63. use Craue\FormFlowBundle\Form\FormFlowInterface;
  64. class CreateGroupWordsFlow extends FormFlow{
  65. //put your code here
  66.  
  67. protected function loadStepsConfig() {
  68. return array(
  69. 'label' => 'data:',
  70. 'form_type' => 'AppBundle\Form\CreateGroupWordsForm',
  71. ),
  72. 'label' => 'words:',
  73. 'form_type' => 'AppBundle\Form\CreateGroupWordsForm',
  74.  
  75. ),
  76. 'label' => 'confirmation',
  77. ),
  78. );
  79. }
  80. public function setDefaultOptions(OptionsResolverInterface $resolver)
  81. {
  82. $resolver->setDefaults(array('language' => false));
  83. // Others if needed, like in the documentation for : 'data_class' => 'VENDOR\Bundle\Entity\MyEntity', 'csrf_protection' => true
  84. }
  85. public function getFormOptions($step, array $options = array()) {
  86. $options = parent::getFormOptions($step, $options);
  87.  
  88. $formData = $this->getFormData();
  89.  
  90. if ($step === 2) {
  91. $options['language'] = $formData->getLanguage1();
  92.  
  93. }
  94.  
  95. return $options;
  96. }
  97.  
  98.  
  99. }


Błąd jest przy metodzie configureOptions, gdyby nie to to by to było skończone.

Ten post edytował Crash89 26.04.2016, 12:12:08
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: 14.10.2025 - 23:29