我有两个实体:事件和城市。我想实现创建事件表单。但其中一个字段应该是包含数据库(城市实体)值的下拉列表。
目前我的控制器中有这个:
$city = $this->getDoctrine()
->getRepository('AtotrukisMainBundle:City')
->findBy(
array(),
array('priority' => 'ASC', 'name' => 'ASC')
);
$event = new Event();
$form = $this->createFormBuilder($event)
->add('name', 'text')
->add('description', 'textarea')
->add('startDate', 'datetime')
->add('endDate', 'datetime')
->add('map', 'text')
->add('city', 'choice', array(
'choice_list' => new ChoiceList($city->getId(), $city->getName())
))
->add('save', 'submit', array('label' => 'Sukurti'))
->getForm();
$form->handleRequest($request);
但是我得到了错误:
Error: Call to a member function getId() on array in /var/www/src/Atotrukis/MainBundle/Controller/EventController.php line 31