我無法收集[採購實體]數據無法保存收集現場數據
我PO實體---創建控制器
public function createAction(Request $request)
{
$entity = new PO();
$form = $this->createForm(new POType(), $entity);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('po_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
我的表單生成器 - PO
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('orderno','text',array('attr'=>array
('placeholder'=>"Order No",'class'=>'input-medium','pattern'=>'[a-zA-Z0-9]+')))
->add('invoiceno','text',array('attr'=>array
('placeholder'=>"Invoice No",'class'=>'input-medium','pattern'=>'[a-zA-Z0-9]+')))
->add('buyervat','text',array('attr'=>array
('placeholder'=>"Buyer VAT No",'class'=>'input-medium')))
->add('sellervat','text',array('attr'=>array
('placeholder'=>"Seller VAT No",'class'=>'input-medium')))
->add('vatamount','number',array('attr'=>array
('placeholder'=>"Vat Amount",'class'=>'input-medium','pattern'=>'[0-9]+')))
->add('orderdate','date')
->add('payment','text',array('attr'=>array
('placeholder'=>"Payment Type:Ref No",'class'=>'input-medium',)))
->add('credit','number',array('attr'=>array
('placeholder'=>"Credit",'class'=>'input-medium',)))
->add('note','text',array('attr'=>array
('placeholder'=>"Note",'class'=>'input-medium',)))
->add('purchases','collection',array(
'type'=>new PurchaseType(),
'allow_add'=> true,
'allow_delete'=>true,
'by_reference' => false,))
;
}
購買實體
<?php
namespace CJ\BusinessBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Purchase
*
* @ORM\Table()
* @ORM\Entity
*/
class Purchase
{
/**
* @ORM\ManyToOne(targetEntity="PO", inversedBy="purchases")
* @ORM\JoinColumn(name="po_id", referencedColumnName="id")
*/
protected $po;
public function __construct()
{
$this->setUpdatedAt(new \DateTime());
}
/**
* Set po
*
* @param \CJ\BusinessBundle\Entity\PO $po
* @return Purchase
*/
public function setPo(\CJ\BusinessBundle\Entity\PO $po = null)
{
$this->po = $po;
return $this;
}
/**
* Get po
*
* @return \CJ\BusinessBundle\Entity\PO
*/
public function getPo()
{
return $this->po;
}
}
我的PO實體
<?php
namespace CJ\BusinessBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* PO
*
* @ORM\Table()
* @ORM\Entity
*/
class PO
{
...
/**
* @ORM\OneToMany(targetEntity="Purchase", mappedBy="po", cascade={"persist"})
*/
protected $purchases;
public function __construct()
{
$this->purchases = new ArrayCollection();
$this->setUpdatedAt(new \DateTime());
}
/**
* Add purchases
*
* @param \CJ\BusinessBundle\Entity\Purchase $purchases
* @return PO
*/
public function addPurchase(\CJ\BusinessBundle\Entity\Purchase $purchases)
{
$this->purchases[] = $purchases;
return $this;
}
/**
* Remove purchases
*
* @param \CJ\BusinessBundle\Entity\Purchase $purchases
*/
public function removePurchase(\CJ\BusinessBundle\Entity\Purchase $purchases)
{
$this->purchases->removeElement($purchases);
}
/**
* Get purchases
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPurchases()
{
return $this->purchases;
}
我在做什麼錯。
什麼是你的問題? – cheesemacfly 2013-04-09 18:45:36