作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想创建一个表单来编辑我的用户。与 ManyToMany 关联的用户和角色。在 UserUsers 实体中,我有一个 $roles 变量,它是 ArrayCollection
:
public function __construct()
{
$this->roles = new ArrayCollection();
}
在我的表单上,我想通过多个选择表单元素向我的用户添加角色。在我的用户表单中:
public function buildForm( FormBuilderInterface $builder, array $options ) {
$builder->add( 'username' )
->add( 'password', 'repeated', array(
'type' => 'password',
'mapped' => false,
'required' => false,
'first_options' => array(
'label' => 'Password' ),
'second_options' => array(
'label' => 'Repeat Password' ) ) )
->add( 'roles', 'choice', array(
'mapped' => false,
'multiple' => true ) );
}
现在我的多选是空的。
如果我将 mapped 设置为 true,我会收到一条错误消息:
UserRoles could not be converted to int in...
我试了很多方法,都没有正确解决这个问题。
最佳答案
对于实体的选择,您应该使用特殊的选择字段类型“实体”(参见 Symfony 手册中的 entity field type)。例如,请参阅我对 similar question 的回答.如果您遇到更多错误,您也可以在 Role Interface and Manage Roles 上找到这个问题。有帮助。
关于forms - symfony2 形成多选与 arraycollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16462179/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!