我的表单有几个用户应填写的字段,但隐藏了三个字段:created_at,updated_at和created_by。
我希望在用户提交表单后更新这些字段,但我不知道如何。
我尝试过类似的东西,但仍然不起作用;
public function executeCreate(sfWebRequest $request)
{
$user = $this->getUser();
$entity = new ProdPProcessIdentifyMethod(); //instance of object which form is about
$entity->setDescription($request->getPostParameter('description'));
$entity->setName($request->getPostParameter('name'));
$entity->setNumber($request->getPostParameter('number'));
$entity->setMarkingsDescription($request->getPostParameter('markings_description'));
$entity->setRegistrationPurpose($request->getAttribute('registration_purpose'));
$entity->setRegistry($request->getPostParameter('registry'));
$entity->setCreatedAt(new DateTime());
$entity->setUpdatedAt(new DateTime());
$entity->setCreatedBy($user->getId());
$entity->setUpdatedBy($user->getId());
$this->form = new ProdPProcessIdentifyMethodForm($entity); //passing object which has values I need
$this->ProdPProcessIdentifyMethod = $this->form->getObject();
$this->processForm($request, $this->form);
$this->setTemplate('new');
}
答案 0 :(得分:0)
我在该代码中没有看到的是$entity->save()
。这是问题吗?
如果您在schema.yml中使用Doctrine和Timestampable
属性,它实际上会为您处理created_at
和updated_at
列。