1. Querying for Objects ( Cara2 nak dapat data objek - 3 cara)
a. Basic (Hok symfony buat doh )
cth : $repository->find($id);
$repository->findOneByName('Foo');
b. Querying for Objects with DQL ( hampir sama dgn SQL)
cth : $em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT p FROM AcmeStoreBundle:Product p WHERE p.price > :price ORDER BY p.price ASC'
)->setParameter('price', '19.99');
$products = $query->getResult(); // return array of result
$product = $query->getSingleResult(); // return 1 object
b. Using Doctrine's Query Builder
see doctrine manual
cth : $repository = $this->getDoctrine()
->getRepository('AcmeStoreBundle:Product');
$query = $repository->createQueryBuilder('p')
->where('p.price > :price')
->setParameter('price', '19.99')
->orderBy('p.price', 'ASC')
->getQuery();
$products = $query->getResult();
No comments:
Post a Comment