提交Symfony 1.4后更新表单数据

时间:2018-02-01 07:21:49

标签: php symfony1 symfony-1.4

我的表单有几个用户应填写的字段,但隐藏了三个字段: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');
  }

1 个答案:

答案 0 :(得分:0)

我在该代码中没有看到的是$entity->save()。这是问题吗?

如果您在schema.yml中使用Doctrine和Timestampable属性,它实际上会为您处理created_atupdated_at列。