I'm trying to access a list of categories I have in a database and put them into a form in Symfony2.
public function productAddAction()
{
$product = new Product();
$categories = $this->getDoctrine()
->getRepository('AudsurShopBundle:Category')
->findAll();
$form = $this->createFormBuilder($product)
->add('category', 'choice', array(
'choices' => $categories, /* this is wrong */
'multiple' => false,
))
->add('name', 'text')
->add('save', 'submit', array('label' => 'Create Task'))
->getForm();
return $this->render('AudsurAdminBundle:Default:new.html.twig', array(
'form' => $form->createView(),
));
}
How do I go from $categories to an object that I can put into the following part, and it complying with what the function expects?
->add('category', 'choice', array(
'choices' => $categories, /* this is wrong */
'multiple' => false,
))
I know this is basic, but I can't seem to find the right keywords to find the answer (what should I have looked for?)