Symfony Repositories: Limit the “R” in CRUD while in development

Limit your CRUD indexAction so it won’t show 5,000+ records and crash with memory error:

 

public function indexAction()
{
  $em = $this->getDoctrine()->getManager();

  // LIMIT LIST to 10 (whatever you put in the 3rd field below:
  $entities = $em ->getRepository(‘MainFormBundle:SomeEntity’)->findBy(
         array(), // $where
         array(), // $orderBy
         10, // $limit
         0 // $offset
);

return $this->render(‘MainFormBundle:SomeEntity:index.html.twig’, array(
   ‘entities’ => $entities,
));
}

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *