我正在以下列方式创建表单:
$form = $this->createFormBuilder($breed)
->add('species', 'entity', array(
'class' => 'BFPEduBundle:Item',
'property' => 'name',
'query_builder' => function(ItemRepository $er){
return $er->createQueryBuilder('i')
->where("i.type = 'species'")
->orderBy('i.name', 'ASC');
}))
->add('breed', 'text', array('required'=>true))
->add('size', 'textarea', array('required' => false))
->getForm()
Run Code Online (Sandbox Code Playgroud)
如何为物种列表框设置默认值?
谢谢你的回复,我道歉,我想我应该重新解释一下我的问题.一旦我有一个从模型中检索的值,如何为物种选择列表中的相应值将该值设置为SELECTED ="yes"?
因此,TWIG视图中的选择选项输出将如下所示:
<option value="174" selected="yes">Dog</option>
Run Code Online (Sandbox Code Playgroud) 我有一个奇怪的问题.这是错误消息:
调用未定义的方法 MyProject\BlogBundle\Entity\Blog::findOneById()
我已经设置了映射,实体类是使用控制台创建的,我已经更新了数据库中的模式.可能导致此问题的原因是什么?
我正在使用symfony2.这是一行:
$blogRepo = $this->get('myproject.blog.repository.blog');
$blog = $blogRepo->findOneById($id);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?