Thursday, May 23, 2013

macam2 contoh Retrieving Data with Doctrine (Querying for Objects)

Fetching Objects from the Database

 


// src/ASF/PembedaBundle/Controller/QuranController.php

class QuranController extends Controller

{
    public function mainAction($surah=null)
    {
                  
        $em = $this->getDoctrine()->getEntityManager();
        $qayat = $em->getRepository('ASFPembedaBundle:Quran')->findBy(array('id' => '001001'));
         /* note : macam2 contoh Retrieving Data with Doctrine (Querying for Objects)
         *     ->find($id); // query by the primary key (usually "id")
         *     ->findOneByName('Foo'); // dynamic method names to find based on a column value
         *     ->findOneById($id);  // dynamic method names to find based on a column value
         *     ->findAll(); // find *all* products
         *     ->findByPrice(19.99); // find a group of products based on an arbitrary column value
         *     ->findOneBy(array('name' => 'foo', 'price' => 19.99)); // query for one product matching be name and price
         *     ->findBy(array('name' => 'foo'),array('price' => 'ASC')); // query for all products matching the name, ordered by price
         *     $em->getRepository('ASFPembedaBundle:Quran')->find($id);
         */

        return $this->render('ASFPembedaBundle:Quran:qmain.html.twig', array(
            'qayat'      => $qayat,
            'comments'  => 'ssssss'
        ));

    }
}

No comments:

Post a Comment