خرید بک لینک

Vote count: 0

How to access the ChoiceType (Radiobutton) submitted value in Symfony2 while working with Doctrine2 I am trying to update the value of eT1 and eT2 property of the events entity. The input value from two different ChoiceType(Radiobutton) is stored in the eT1 and eT2 variables after the user submits. when i try to use the $events->setET1($eT1) method, it gives an error - Notice: Undefined variable: eT1 500 Inteal Server Error - ContextErrorException Here is my Controller code

<?php

namespace AppBundleController;

use AppBundleEntityevents;
//use AppBundleEntityeventtype;
use AppBundleEntityusers;
use SensioBundleFrameworkExtraBundleConfigurationRoute;
use SymfonyBundleFrameworkBundleControllerController;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentFormExtensionCoreTypeSubmitType;
use SymfonyComponentFormExtensionCoreTypeChoiceType;

class DefaultController extends Controller {

    /**
     * @Route("/home", name="homepage")
     */
    public function indexAction(Request $request) {
        $events = new events();

        $form = $this->createFormBuilder($events)
                ->add('eT1', ChoiceType::class, array(
                    'choices' => array(
                        'Poker' => 1,
                        'Chess' => 2,
                        'Cricket' => 3,
                        'Marbles' => 4,
                        'Football' => 5,
                    ),
                    'choices_as_values' => true,
                    'expanded' => true,
                    'multiple' => false,
                    'label' => 'Choose After Breakfast Event',
                ))
                ->add('eT2', ChoiceType::class, array(
                    'choices' => array(
                        'Poker' => 1,
                        'Chess' => 2,
                        'Cricket' => 3,
                        'Marbles' => 4,
                        'Football' => 5,
                    ),
                    'choices_as_values' => true,
                    'expanded' => true,
                    'multiple' => false,
                    'label' => 'Choose After Snacks Event',
                ))
                ->add('save', SubmitType::class, array('label' => 'Submit'))
                ->getForm();

        if ($request->isMethod('POST')) {
            $form->submit($request);

            $user = $this->container->get('security.context')->getToken()->getUser();
            $events->setUser($user);

            $x = $events->getUser()->getID();

            if ($form->isValid()) {
                //$em = $this->getDoctrine()->getManager();

                $events = $this->getDoctrine()->getRepository('AppBundle:events')->findOneBy(array('user' => $x));
//                var_dump($events);
//                exit;
                if (!$events) {
                    echo 'insert';
                    // tells Doctrine you want to (eventually) save the Product (no queries yet)
                    $em->persist($events);

                    // actually executes the queries (i.e. the INSERT query)
                    $em->flush();
                    retu $this->redirectToRoute('homepage');
                } else {
                    echo 'update';
//                    var_dump($form);
//                    exit;
                    $events->setET1($eT1);
                    $events->setET2($eT2);
//                  $em->persist($events);
                    $em->flush();
                    retu $this->redirectToRoute('homepage');
                }
            }
        }

        retu $this->render('default/index.html.twig', array(
                    'form' => $form->createView(),
        ));
    }

}

Below is the users entity

<?php

namespace AppBundleEntity;

use FOSUserBundleModelUser as BaseUser;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
use DoctrineCommonCollectionsArrayCollection;

/**
 * users
 *
 * @ORMTable(name="users")
 * @ORMEntity(repositoryClass="AppBundleRepositoryusersRepository")
 */
class users extends BaseUser
{
    /**
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * Get id
     * @retu integer 
     */
    public function getId()
    {
        retu $this->id;
    }

    /**
     * @ORMOneToOne(targetEntity="events", mappedBy="user")
     */
    protected $event;


//    public function __construct()
//    {
//        parent::__construct(); 
//         }

    }

Below is the events entity where the setET1($eT1) is defined

<?php

namespace AppBundleEntity;

use DoctrineORMMapping as ORM;

/**
 * events
 *
 * @ORMTable(name="events")
 * @ORMEntity(repositoryClass="AppBundleRepositoryeventsRepository")
 */
class events {

    /**
     * @var int
     *
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var int
     *
     * @ORMColumn(name="ET1", type="integer")
     */
    protected $eT1;

    /**
     * @var int
     *
     * @ORMColumn(name="ET2", type="integer")
     */
    protected $eT2;

    /**
     * @ORMOneToOne(targetEntity="users", inversedBy="event")
     * @ORMJoinColumn(name="user_id", referencedColumnName="id")
     */
        protected $user;

    /**
     * Get id
     *
     * @retu integer 
     */
    public function getId() {
        retu $this->id;
    }

    /**
     * Set user
     *
     * @param users $user
     * @retu events
     */
    public function setUser($user) {
        $this->user = $user;

        retu $this;
    }

    /**
     * Get user
     *
     * @retu events
     */
    public function getUser() {
        retu $this->user;
    }


    /**
     * Set eT1
     *
     * @param integer $eT1
     * @retu events
     */
    public function setET1($eT1) {
        $this->eT1 = $eT1;

        retu $this;
    }

    /**
     * Get eT1
     *
     * @retu integer 
     */
    public function getET1() {
        retu $this->eT1;
    }

    /**
     * Set eT2
     *
     * @param integer $eT2
     * @retu events
     */
    public function setET2($eT2) {
        $this->eT2 = $eT2;

        retu $this;
    }

    /**
     * Get eT2
     *
     * @retu integer 
     */
    public function getET2() {
        retu $this->eT2;
    }

//    public function __construct()
//    {
//        parent::__construct();
//    }
}

asked 4 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 2 ارديبهشت 1395 ساعت: 17:33

صفحه بندی