0
votes

I have form which has couple fields which user should fill, but three fields are hidden: created_at, updated_at, and created_by.

I want to update those fields after user subbmit the form, but I have no idea how.

I tried something like this, but still not works;

  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

1 Answers

0
votes

What I don't see in that code is a $entity->save(). Is that the problem?

If you are using Doctrine and the Timestampable property in your schema.yml, it will actually take care of the created_at and updated_at columns for you.