1

I've tried searching about updating data in Symfony2 but look like all tutorials need few normal steps to do this :

  1. Manager initialisation $em = $this->getDoctrine()->getManager();
  2. Make Entity with criteria $entity = $em->getRepository('bundle')->find($id);
  3. Create Form $form = $this->createForm(new Type(), $entity);
  4. Bind with request $editForm->handleRequest($request);
  5. Flush data $em->flush();

Let say that I have custom form in twig and do manual getRequest in controller $variable = $request->request->get('name');. Is there any way I can do to update this data for specific ID in entity $entity = $em->getRepository('bundle')->find($id); without create a form for flush my data?

Because I need to update this variable for many ID in my database using iteration. Let say that I have thousands data need to updated with this value. I'm worried if creating form will impact to performance and time.

0

1 Answer 1

5

Simply set your data directly in your entity using your setters and then flush:

$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('Bundle:Entity')->find($id);

$entity->setSomeProperty($propertyValue);

$em->flush();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.