Guest User

Untitled

a guest
Apr 17th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <?php
  2. namespace AppBundle\Controller;
  3. use AppBundle\AppBundle;
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  9. use AppBundle\Entity\Plachta;
  10. class ChangeSheetController extends Controller
  11. {
  12. const SHEET_PARAM = 'sheet';
  13. public function viewAction(Request $request, $idPlachta){
  14. $em = $this->getDoctrine()->getManager();
  15. $plachty = $em->getRepository('AppBundle:Plachta')->findAll(array('idPlachta' => $idPlachta));
  16. $choices = [];
  17. foreach ($plachty as $plachta) {
  18. $choices[$plachta->getOpis()] = $plachta->getIdPlachta();
  19. }
  20.  
  21. $form = $this->createFormBuilder()
  22. ->setAction($this->generateUrl('changesheet_view'))
  23. ->setMethod('GET')
  24. ->add('plachta', ChoiceType::class,array('label'=>'Plachta','choices'=>$choices,'attr'=>array('class'=>'form-control', 'style'=>'margin-bottom:15px')))
  25. ->add('Wybierz', SubmitType::class)
  26. ->getForm();
  27.  
  28. $form->handleRequest($request);
  29. if ($form->isSubmitted() && $form->isValid()) {
  30. // formularz wyslany, wsadzamy do sesji
  31. $request->getSession()->set('plachta', $form['plachta']->getData());
  32. }
  33. $request->getSession()->get('plachta');
  34.  
  35. return $this->render('inne/profil.html.twig', array(
  36. 'form' =>$form->createView()));
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment