Symfony Operations
$request->get('comment')
return View::create(null, Response::HTTP_CREATED);
return View::create(null, Response::HTTP_BAD_REQUEST);
##Doctrine
$product = $this->getDoctrine()
->getRepository('AppBundle:Product')
->find($productId);
$product = new Product();
$product->setName('Keyboard');
$product->setPrice(19.99);
$product->setDescription('Ergonomic and stylish!');
$em = $this->getDoctrine()->getManager();
// tells Doctrine you want to (eventually) save the Product (no queries yet)
$em->persist($product);
// actually executes the queries (i.e. the INSERT query)
$em->flush();
$result = $qb->getQuery()
->setFirstResult(0)
->setMaxResults(2);
->getResult();
use Doctrine\DBAL\Connection
$conn = $this->getEntityManager()
->getConnection();
$sql = "SELECT * FROM articles WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bindValue(1, $id);
$stmt->execute();
OR
$em = $this->getEntityManager();
$rsm = new ResultSetMapping();
$query = $em->createNativeQuery('
SELECT * FROM wb_trainers_racehorses wtr
LEFT JOIN wb_hnd_horses
ON wb_hnd_horses.id = wb_trainers_racehorses.animalId
WNERE wtr = :id
', $rsm);
$query->setParameter($id, 'id');
$records = $query->getResult();
$qb = $this->entityManager->createQueryBuilder();
$qb->select('a', 'u')
->from('Credit\Entity\UserCreditHistory', 'a')
->leftJoin(
'User\Entity\User',
'u',
\Doctrine\ORM\Query\Expr\Join::WITH,
'a.user = u.id'
)
->where('u = :user')
->setParameter('user', $users)
->orderBy('a.created_at', 'DESC');
return $qb->getQuery()->getResult();
$qb = $this->createQueryBuilder('a');
$query = $qb->getQuery();
// Show SQL
$sql = $query->getSQL();
// Show Parameters
$parameters = $query->getParameters();