0

私のコントローラーコードは

public function checkoutAction(Request $request) {
        $securityContext = $this->container->get('security.context');
        $request = $this->getRequest();
        $form = $this->createForm(new RequestRunnerType() );
        $data = array();

        if ($request->getMethod() == 'POST') {
            $orderService = $this->container->get('order_service');
            $paymentMethod = $request->request->get('paymentMethod');
            if ($paymentMethod == 'requsetRunner') {
                $form->bind($request->request->get('requestRunner'));
                if ($form->isValid()) {
                    //problem is here
                    $address = $form->getData();
                    $return = $orderService->createOrder($paymentMethod, $address['requestRunner']);
                }
            }
        }
    }

フォームクラスコードは

   public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('id', 'hidden')
                ->add('buildingNo', 'text',array(
                    'mapped' => false
                ))
                ->add('floorNo', 'text',array(
                    'mapped' => false
                ))
                ->add('street', 'text',array(
                    'mapped' => false
                ))
                ->add('city', 'text')
                ->add('landmark', 'text',array(
                    'mapped' => false
                ))
                ->add('apartmentNo', 'text',array(
                    'mapped' => false
                ))
                ->add('name', 'text')
                ->add('phoneNo', 'text')
                ->add('notes', 'textarea')
                ->add('currency', 'choice', array(
                    'choices' => array(
                        'EGP' => 'EGP',
                        'USD' => 'USD'
                    ))
        );
    }

私のエンティティ

<?php

namespace myapp\bundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * RequestRunner
 *
 * @ORM\Table(name="request_runner")
 * @ORM\Entity
 */
class RequestRunner
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\Column(name="orderId", type="integer", nullable=false)
     */
    private $orderid;

    /**
     * @var integer
     *
     * @ORM\Column(name="customerId", type="integer", nullable=false)
     */
    private $customerid;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(name="phoneNo", type="string", length=45, nullable=true)
     */
    private $phoneno;

    /**
     * @var string
     *
     * @ORM\Column(name="mobileNo", type="string", length=45, nullable=false)
     */
    private $mobileno;

    /**
     * @var string
     *
     * @ORM\Column(name="address", type="string", length=255, nullable=false)
     */
    private $address;

    /**
     * @var string
     *
     * @ORM\Column(name="city", type="string", length=255, nullable=true)
     */
    private $city;

    /**
     * @var string
     *
     * @ORM\Column(name="notes", type="text", nullable=true)
     */
    private $notes;

    /**
     * @var string
     *
     * @ORM\Column(name="comments", type="text", nullable=true)
     */
    private $comments;

    /**
     * @var float
     *
     * @ORM\Column(name="weight", type="decimal", nullable=true)
     */
    private $weight;

    /**
     * @var string
     *
     * @ORM\Column(name="appointment_from", type="string", length=255, nullable=false)
     */
    private $appointmentFrom;

    /**
     * @var string
     *
     * @ORM\Column(name="appointment_to", type="string", length=255, nullable=true)
     */
    private $appointmentTo;

    /**
     * @var float
     *
     * @ORM\Column(name="amount", type="decimal", nullable=false)
     */
    private $amount;

    /**
     * @var float
     *
     * @ORM\Column(name="deliveryFees", type="decimal", nullable=false)
     */
    private $deliveryfees;

    /**
     * @var string
     *
     * @ORM\Column(name="type", type="string", length=255, nullable=false)
     */
    private $type;

    /**
     * @var string
     *
     * @ORM\Column(name="employee", type="string", length=255, nullable=false)
     */
    private $employee;

    /**
     * @var string
     *
     * @ORM\Column(name="status", type="string", length=255, nullable=false)
     */
    private $status;

    /**
     * @var string
     *
     * @ORM\Column(name="courier", type="string", length=255, nullable=false)
     */
    private $courier;

    /**
     * @var integer
     *
     * @ORM\Column(name="time", type="integer", nullable=false)
     */
    private $time;

    /**
     * @var string
     *
     * @ORM\Column(name="waybill", type="string", length=255, nullable=true)
     */
    private $waybill='';

    /**
     * @var string
     *
     * @ORM\Column(name="urlWaybill", type="string", length=255, nullable=true)
     */
    private $urlwaybill;

    /**
     * @var float
     *
     * @ORM\Column(name="rate", type="decimal", nullable=false)
     */
    private $rate;

    /**
     * @var string
     *
     * @ORM\Column(name="currency", type="string", length=45, nullable=false)
     */
    private $currency;

    /**
     * @var string
     *
     * @ORM\Column(name="deliveryTime", type="string", length=255, nullable=false)
     */
    private $deliverytime=0;

    /**
     * @var string
     ***
     * @ORM\Column(name="chequeNo", type="string", length=45, nullable=false)
     */
    private $chequeno=0;
}

私の問題:**リクエストをフォームにバインドすると、オブジェクトがNULLでいっぱいになり、印刷すると$request->request->all(); 、以下のようにポストリクエストで値が取得されます

array (size=2)
  'paymentMethod' => string 'requsetRunner' (length=13)
  'requestRunner' => 
    array (size=12)
      'city' => string 'Cairo' (length=5)
      'buildingNo' => string '' (length=0)
      'street' => string '38 Hassnin Abdel Kader, Nasr City' (length=33)
      'apartmentNo' => string '' (length=0)
      'floorNo' => string '0' (length=1)
      'id' => string '' (length=0)
      'name' => string '' (length=0)
      'phoneNo' => string '' (length=0)
      '_token' => string '1a8d21d49a5eb612a8b863b792b89b0ed0bb8b67' (length=40)
      'currency' => string 'EGP' (length=3)
      'landmark' => string 'Next to supermarket' (length=19)
      'notes' => string '' (length=0)

私がしようとしました

$form->bind($request->request->get('requestRunner'));

$form->bind($request));

Symfony 2.2は配列をフェッチし、ドキュメントが言うようにフォームを取得する必要がありますが、両方が機能していません

4

1 に答える 1