我将此代码添加到当前实体,并进行了Doctrine模式的更新:
/**
* @var string
*
* @ORM\Column(name="ftt_code", type="string", nullable=true)
*/
private $fttCode;
/**
* @return string
*/
public function getFttCode()
{
return $this->fttCode;
}
/**
* @param string $fttCode
*/
public function setFttCode($fttCode)
{
$this->fttCode = $fttCode;
}
我也将此添加到了表单生成器:
->add('fttCode', TextType::class, ['label' => 'FTT Kód zóny', 'required' => false])
但是当我将记录插入数据库时,此值未插入并且为空。
任何人都知道问题出在哪里吗?
编辑:这是控制器代码
if ($form->isSubmitted() && $form->isValid()) {
$security = $this->get('app.be_security.service');
if ($security->isAdmin() === false) {
$providers = $security->getReferenceListByClass(Provider::class);
if(count($providers) == 1) {
$zone->setProvider($providers);
}
}
$em = $this->getDoctrine()->getManager();
$em->persist($zone);
$em->flush();
$this->addFlash('notice', $this->get('translator')->trans("forms.message.inserted"));
if($zone->isStreetDefinedZones()) {
return $this->redirectToRoute('zone_edit', ["id" => $zone->getId()]);
} else {
return $this->redirectToRoute('zone_index');
}
}
[如果还没有,请添加]>
'data_class'=> YourEntity :: class
到您的表单类型的选项解析器。
然后替换
$ em-> persist($ zone);
with
$ em-> persist($ form-> getData());