Symfony 3 Catchable致命错误:类Symfony \ Component \ Form \ Form的对象无法转换为字符串

时间:2016-11-23 10:00:54

标签: symfony symfony-3.1

我知道有很多这样的问题,但是在阅读之后我无法解决我的问题。

实体

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Orders
 *
 * @ORM\Table(name="orders")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\OrdersRepository")
 */
class Orders
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="shopOrderId", type="string", unique=true)
     */
    private $shopOrderId;
    /**
     * @var string
     *
     * @ORM\Column(name="postBuyFormMsg", type="string")
     */
    private $postBuyFormMsg;

    /**
     * @var boolean
     *
     * @ORM\Column(name="invoice", type="boolean")
     */
    private $invoice;

    /**
     * @var string
     *
     * @ORM\Column(name="payType", type="string")
     */
    private $payType;

    /**
     * @var string
     *
     * @ORM\Column(name="payStatus", type="string")
     */
    private $payStatus;
    /**
     * @var integer
     *
     * @ORM\Column(name="shipmentType", type="integer")
     */
    private $shipmentType;

    /**
     * @var datetime
     *
     * @ORM\Column(name="orderDate", type="datetime")
     */
    private $orderDate;
//    /**
//     * @var integer
//     *
//     * @ORM\Column(name="status", type="integer")
//     */
//    private $status;
    /**
     * @var boolean
     *
     * @ORM\Column(name="verified", type="boolean")
     */
    private $verified = 0;
    /**
     * @var boolean
     *
     * @ORM\Column(name="sent", type="boolean")
     */
    private $sent = 0;
    /**
     * @var boolean
     *
     * @ORM\Column(name="canceled", type="boolean")
     */
    private $canceled = 0;
    /**
     * @var string
     *
     * @ORM\Column(name="adminComment", type="string", nullable=true)
     */
    private $adminComment;
    /**
     * @ORM\ManyToOne(targetEntity="Customer", inversedBy="id")
     * @ORM\JoinColumn(name="customerId", referencedColumnName="id")
     */
    private $customerId;


    /**
     * @ORM\OneToMany(targetEntity="OrdersDetails", mappedBy="orderId")
     */
    private $orderId;
    /**
     * @ORM\OneToMany(targetEntity="OrderData", mappedBy="orderData")
     */
    private $orderData;
    /**
     * @ORM\OneToMany(targetEntity="OrderHistory", mappedBy="orderHistory")
     */
    private $orderHistory;

    /**
     * @ORM\ManyToOne(targetEntity="Shops", inversedBy="id")
     * @ORM\JoinColumn(name="shopId", referencedColumnName="id")
     */
    private $shopId;


    /**
     * Constructor
     */
    public function __construct()
    {
        $this->orderId = new \Doctrine\Common\Collections\ArrayCollection();
        $this->orderData = new \Doctrine\Common\Collections\ArrayCollection();
        $this->orderHistory = new \Doctrine\Common\Collections\ArrayCollection();
    }

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

    /**
     * Set shopOrderId
     *
     * @param string $shopOrderId
     *
     * @return Orders
     */
    public function setShopOrderId($shopOrderId)
    {
        $this->shopOrderId = $shopOrderId;

        return $this;
    }

    /**
     * Get shopOrderId
     *
     * @return string
     */
    public function getShopOrderId()
    {
        return $this->shopOrderId;
    }

    /**
     * Set postBuyFormMsg
     *
     * @param string $postBuyFormMsg
     *
     * @return Orders
     */
    public function setPostBuyFormMsg($postBuyFormMsg)
    {
        $this->postBuyFormMsg = $postBuyFormMsg;

        return $this;
    }

    /**
     * Get postBuyFormMsg
     *
     * @return string
     */
    public function getPostBuyFormMsg()
    {
        return $this->postBuyFormMsg;
    }

    /**
     * Set invoice
     *
     * @param boolean $invoice
     *
     * @return Orders
     */
    public function setInvoice($invoice)
    {
        $this->invoice = $invoice;

        return $this;
    }

    /**
     * Get invoice
     *
     * @return boolean
     */
    public function getInvoice()
    {
        return $this->invoice;
    }

    /**
     * Set payType
     *
     * @param string $payType
     *
     * @return Orders
     */
    public function setPayType($payType)
    {
        $this->payType = $payType;

        return $this;
    }

    /**
     * Get payType
     *
     * @return string
     */
    public function getPayType()
    {
        return $this->payType;
    }

    /**
     * Set payStatus
     *
     * @param string $payStatus
     *
     * @return Orders
     */
    public function setPayStatus($payStatus)
    {
        $this->payStatus = $payStatus;

        return $this;
    }

    /**
     * Get payStatus
     *
     * @return string
     */
    public function getPayStatus()
    {
        return $this->payStatus;
    }

    /**
     * Set shipmentType
     *
     * @param integer $shipmentType
     *
     * @return Orders
     */
    public function setShipmentType($shipmentType)
    {
        $this->shipmentType = $shipmentType;

        return $this;
    }

    /**
     * Get shipmentType
     *
     * @return integer
     */
    public function getShipmentType()
    {
        return $this->shipmentType;
    }

    /**
     * Set orderDate
     *
     * @param \DateTime $orderDate
     *
     * @return Orders
     */
    public function setOrderDate($orderDate)
    {
        $this->orderDate = $orderDate;

        return $this;
    }

    /**
     * Get orderDate
     *
     * @return \DateTime
     */
    public function getOrderDate()
    {
        return $this->orderDate;
    }

    /**
     * Set verified
     *
     * @param boolean $verified
     *
     * @return Orders
     */
    public function setVerified($verified)
    {
        $this->verified = $verified;

        return $this;
    }

    /**
     * Get verified
     *
     * @return boolean
     */
    public function getVerified()
    {
        return $this->verified;
    }

    /**
     * Set sent
     *
     * @param boolean $sent
     *
     * @return Orders
     */
    public function setSent($sent)
    {
        $this->sent = $sent;

        return $this;
    }

    /**
     * Get sent
     *
     * @return boolean
     */
    public function getSent()
    {
        return $this->sent;
    }

    /**
     * Set canceled
     *
     * @param boolean $canceled
     *
     * @return Orders
     */
    public function setCanceled($canceled)
    {
        $this->canceled = $canceled;

        return $this;
    }

    /**
     * Get canceled
     *
     * @return boolean
     */
    public function getCanceled()
    {
        return $this->canceled;
    }

    /**
     * Set adminComment
     *
     * @param string $adminComment
     *
     * @return Orders
     */
    public function setAdminComment($adminComment)
    {
        $this->adminComment = $adminComment;

        return $this;
    }

    /**
     * Get adminComment
     *
     * @return string
     */
    public function getAdminComment()
    {
        return $this->adminComment;
    }

    /**
     * Set customerId
     *
     * @param \AppBundle\Entity\Customer $customerId
     *
     * @return Orders
     */
    public function setCustomerId(\AppBundle\Entity\Customer $customerId = null)
    {
        $this->customerId = $customerId;

        return $this;
    }

    /**
     * Get customerId
     *
     * @return \AppBundle\Entity\Customer
     */
    public function getCustomerId()
    {
        return $this->customerId;
    }

    /**
     * Add orderId
     *
     * @param \AppBundle\Entity\OrdersDetails $orderId
     *
     * @return Orders
     */
    public function addOrderId(\AppBundle\Entity\OrdersDetails $orderId)
    {
        $this->orderId[] = $orderId;

        return $this;
    }

    /**
     * Remove orderId
     *
     * @param \AppBundle\Entity\OrdersDetails $orderId
     */
    public function removeOrderId(\AppBundle\Entity\OrdersDetails $orderId)
    {
        $this->orderId->removeElement($orderId);
    }

    /**
     * Get orderId
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOrderId()
    {
        return $this->orderId;
    }

    /**
     * Add orderDatum
     *
     * @param \AppBundle\Entity\OrderData $orderDatum
     *
     * @return Orders
     */
    public function addOrderDatum(\AppBundle\Entity\OrderData $orderDatum)
    {
        $this->orderData[] = $orderDatum;

        return $this;
    }

    /**
     * Remove orderDatum
     *
     * @param \AppBundle\Entity\OrderData $orderDatum
     */
    public function removeOrderDatum(\AppBundle\Entity\OrderData $orderDatum)
    {
        $this->orderData->removeElement($orderDatum);
    }

    /**
     * Get orderData
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOrderData()
    {
        return $this->orderData;
    }

    /**
     * Add orderHistory
     *
     * @param \AppBundle\Entity\OrderHistory $orderHistory
     *
     * @return Orders
     */
    public function addOrderHistory(\AppBundle\Entity\OrderHistory $orderHistory)
    {
        $this->orderHistory[] = $orderHistory;

        return $this;
    }

    /**
     * Remove orderHistory
     *
     * @param \AppBundle\Entity\OrderHistory $orderHistory
     */
    public function removeOrderHistory(\AppBundle\Entity\OrderHistory $orderHistory)
    {
        $this->orderHistory->removeElement($orderHistory);
    }

    /**
     * Get orderHistory
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOrderHistory()
    {
        return $this->orderHistory;
    }

    /**
     * Set shopId
     *
     * @param \AppBundle\Entity\Shops $shopId
     *
     * @return Orders
     */
    public function setShopId(\AppBundle\Entity\Shops $shopId = null)
    {
        $this->shopId = $shopId;

        return $this;
    }

    /**
     * Get shopId
     *
     * @return \AppBundle\Entity\Shops
     */
    public function getShopId()
    {
        return $this->shopId;
    }
}

控制器

public function orderAction(Request $request, $id)
{
    $em = $this->getDoctrine()->getManager();
    $order = $em->getRepository('AppBundle:Orders')->findOneBy(array('id' => $id));
    $adminCommentForm = $this->createForm(adminCommentType::class, $order);

    if ($adminCommentForm->isValid() && $adminCommentForm->isSubmitted()) {
        $order->setAdminComment($adminCommentForm);
        $em->persist($order);
        $em->flush();
    }

    return $this->render(':Orders:order.html.twig',
        array(

            'adminCommentForm' => $adminCommentForm->createView(),

        )
    );
}

FormType

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class adminCommentType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('adminComment',TextareaType::class,array('label'=>false))
            ->add('save', SubmitType::class, array('label' => 'Dodaj'));

    }

    public function configureOptions(OptionsResolver $resolver)
    {

    }

    public function getName()
    {
        return 'app_bundleadmin_comment_type';
    }
}

我尝试将__toString函数添加到我在此处描述的实体symfony2 Catchable Fatal Error: Object of class could not be converted to string,但它也不起作用。如何使用__toString方法返回多个变量并最终使其工作?

0 个答案:

没有答案