我如何创建一个选择列表与Symfony 2中的数据库表中的值?Symfony 2表单与选择列表
我有2个实体:学生和课堂有多对一的关系,我需要创建与如下因素字段的表单:名,姓,年龄,教室(选择列表从可用的类)。
在我学生表格我有
$builder
->add('name')
->add('surname')
->add('age')
->add('classroom', new ClassroomType())
;
在我课堂形式我有这样的:
$classrooms =$this->getDoctrine()->getRepository('UdoCatalogBundle:Classroom')->findAll();
$builder
->add('clasa','choice',array('choices' => array($classrooms->getId() => $classrooms->getName())));
我得到这个以下错误:
Fatal error: Call to undefined method Udo\CatalogBundle\Form\ClassroomType::getDoctrine() in /var/www/html/pos/src/Udo/CatalogBundle/Form/ClassroomType.php on line 13
类问候, Cearnau Dan
这里的解释:http://groups.google.com/group/symfony2/browse_thread/thread/ da8f72b33f9f93ba – tttony