Skip to content

Processing data

Apodemus Erectus edited this page Jun 10, 2020 · 16 revisions

This guide is about fetching data from your database and sending data to your database using Symfony.

The EntityManager

"The EntityManager is your friend. He can fetch data, send data, a really good guy overall." - Bryan Kho

This is the EntityManager, it can fetch data and send data from and to your database. You can access the Entity Manager from your controller.

$entityManager = $this->getDoctrine()->getManager();

You can also access the EntityManager via the EntityManagerInterface object, which you can add as an argument to your method inside your controller.

// don't forget the import
use Doctrine\ORM\EntityManagerInterface;

yourMethod(EntityManagerInterface $entityManager) {

}

fetch data

You can use the getRepository() method of the EntityManager to find an object.

$product = $entityManager->getRepository(Product::class)->find($id);

besides the find() method on the Repository, you can also use findBy(), findAll() and findOneBy().

Clone this wiki locally