我尝试使用sonata_type_model
或entity
类型呈现类似于the SO question的多项选择下拉菜单。我的实体Property
与manyToMany
到Feature
oneToMany
FeatureType
。多选下拉列表正在Property property表单中实现。
我找到了the group_by option。但是我使用entity
收到了警告,并使用sonata_type_model
得到了错误的渲染。
->add('features', 'entity', array(
'class' => 'MyBundle:Feature',
'multiple' => true,
'group_by' => 'featureType'
))
警告:isset中的非法偏移类型或者在第334行的vendor / symfony / symfony / src / Symfony / Component / Form / ChoiceList / Factory / DefaultChoiceListFactory.php中为空
->add('features', 'sonata_type_model', array(
'multiple' => true,
'btn_add' => null,
'group_by' => 'featureType'
))
它只渲染下拉列表中的值,例如
我尝试了choices
,但收到了错误
->add('features', 'sonata_type_model', array(
'multiple' => true,
'required' => false,
'btn_add' => null,
'choices' => $this->getFeatureOptionsWithGroup()
))
警告:get_class()期望参数1是对象,在第58行的vendor / doctrine / common / lib / Doctrine / Common / Util / ClassUtils.php中给出的数组
我尝试了choice_list
,但收到了错误
->add('features', 'sonata_type_model', array(
'multiple' => true,
'required' => false,
'btn_add' => null,
'choice_list' => $this->getFeatureOptionsWithGroup()
))
选项" choice_list"值数组应该是" null"或" Symfony \ Component \ Form \ ChoiceList \ ChoiceListInterface",但类型为" array"在vendor / symfony / symfony / src / Symfony / Component / OptionsResolver / OptionsResolver.php第888行
方法getFeatureOptionsWithGroup()
像这样返回数组
array(
'Group 1' => array(
1 => 'Feature 1'
2 => 'Feature 2'
),
'Group 2' => array(
3 => 'Feature 3'
4 => 'Feature 4'
)
)
我使用ModelChoiceList
更新了该方法,但在使用choices
时遇到了同样的错误。
警告:get_class()期望参数1是对象,在第58行的vendor / doctrine / common / lib / Doctrine / Common / Util / ClassUtils.php中给出的数组
private function getFeatureOptionsWithGroup()
{
return new ModelChoiceList(
$this->modelManager,
'MyBundle:Feature',
null,
null,
$this->getRepository('MyBundle:Feature')->getFeatureOptionsWithGroup()
);
}
我希望我有机会在没有模板覆盖的情况下渲染它。任何帮助将不胜感激。
答案 0 :(得分:3)
使用类型Dim cnn As New OleDb.OleDbConnection
cnn = New OleDb.OleDbConnection
cnn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Users\Ashe\Documents\Visual Studio 2010\Projects\WindowsApplication1\Guidance System.accdb")
Dim mydate As DateTime
mydate = DateTimePicker1.Value
mydate.ToString("yyyy-MM-dd")
Dim AddCol = "ALTER TABLE Attendance " & _
"ADD '" & mydate & "' varchar(100);"
Using cmd = New OleDbCommand(AddCol, cnn)
cnn.Open()
cmd.ExecuteNonQuery()
End Using
entity
确保您的函数->add('features', 'entity', [
'class' => 'MyBundle:Feature',
'property' => 'name',
'choices' => $this->getFeatureOptionsWithGroup(),
'multiple' => true,
'required' => false,
'btn_add' => null,
])
像这样返回
getFeatureOptionsWithGroup()
答案 1 :(得分:1)
执行此操作的最佳方法是使用group_by
选项。
因此,根据您的情况,您需要在$property
实体中传递FeatureType
字段的名称,然后在您的Property实体上传递,您需要实现__toString()
函数,该函数应该是属性为字符串。
解释:
在FeatureType
实体表上,属性关联由property_id
映射为外键,Doctrine为您查询,因此您只需指定要对其进行分组的方式。