0
我有一個表格由formbuilder表單提交錯誤data_class FormView控件
public function buildForm(FormBuilderInterface $builder, array $options){
$query = $this->em->createQueryBuilder();
$query->select('sn.serial_nr')
->from('KopictAdminBundle:SerialNumber', 'sn');
$serialnumbers = $query->getQuery()->getResult();
$options = array();
foreach($serialnumbers as $serialnumber){
$options[$serialnumber['serial_nr']] = $serialnumber['serial_nr'];
}
$builder->add("serial_nr","text");
}
它正確地顯示了形式建造,但是當我提交我得到這個錯誤:
"The form's view data is expected to be an instance of class Kopict\AdminBundle\Entity\SerialNumber, but is a(n) string. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms a(n) string to an instance of Kopict\AdminBundle\Entity\SerialNumber." at /var/www/kopadmin/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 373
這是怎麼了我的實體外觀像:
class SerialNumber
{
/**
* @var integer $id
*/
private $id;
/**
* @var interger $product_revision_id
*/
private $product_revision_id;
/**
* @var interger $booking_id
*/
private $booking_id;
/**
* @var string $serial_nr
*/
public $serial_nr;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set product_revision_id
*
* @param integer $product_revision_id
* @return SerialNumber
*/
public function setProduct_revision_id($product_revision_id)
{
$this->product_revision_id = $product_revision_id;
return $this;
}
/**
* Get product_revision_id
*
* @return integer
*/
public function getProduct_revision_id()
{
return $this->product_revision_id;
}
/**
* Set booking_id
*
* @param integer $booking_id
* @return SerialNumber
*/
public function setBooking_id($booking_id)
{
$this->booking_id = $booking_id;
return $this;
}
/**
* Get booking_id
*
* @return integer
*/
public function getBooking_id()
{
return $this->booking_id;
}
/**
* Set serial_nr
*
* @param string $serial_nr
* @return SerialNumber
*/
public function setSerial_nr($serial_nr)
{
$this->serial_nr = $serial_nr;
return $this;
}
/**
* Get serial_nr
*
* @return string
*/
public function getSerial_nr()
{
return $this->serial_nr;
}
}
我試圖添加data_class,但我找不到添加它的好地方,因爲c頌歌不斷給我同樣的錯誤。