まず第一に、私を助けようとして読んでくれてありがとう。私はsymfonyが初めてです。
プロパティ FechaAlta (SingUpDate) を持つエンティティがあります。ユーザーのサインアップ日を保存したい
/**
* @var date
*
* @ORM\Column(name="fechaAlta", type="datetime")
*/
private $fechaAlta;
/**
* Set fechaAlta
*
* @return Promotor
*/
public function setFechaAlta()
{
$this->fechaAlta = new \DateTime('now');
return $this;
}
フォームに隠しフィールドを作成せずにこの日付を保存する最善の方法を知りたいです。
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nombre')
#->add('slug')
->add('fechaAlta')
;
}
フォームフィールド「fechaAlta」を削除しようとしましたが、次のエラーが発生し続けます
An exception occurred while executing 'INSERT INTO Promotor (nombre, slug, fechaAlta) VALUES (?, ?, ?)' with params {"1":"Prueba","2":"prueba","3":null}:
SQLSTATE [23000]: 整合性制約違反: 1048 列 'fechaAlta' を null にすることはできません
newAction() で、$promotor->setFechaAlta(); を呼び出します。現在の日付を保存する必要があります。
public function newAction()
{
$promotor = new Promotor();
$promotor->setFechaAlta();
$form = $this->createForm(new PromotorType(), $promotor);
return $this->render('PromotorBundle:Promotor:new.html.twig', array(
'entity' => $promotor,
'form' => $form->createView(),
));
}
どうもありがとう