Symfony 2.8 使用 Propel 绑定下拉菜单
Symfony 2.8 Bind Dropdown using Propel
我已经尝试绑定下拉列表并在我的代码中添加以下代码
OrganizationBundle->Form->Tyep->OrganizationType.php 文件:
use Admin\SalesTeamBundle\Model\SalesTeam;
use Admin\SalesTeamBundle\Model\SalesTeamQuery;
use Admin\SalesTeamBundle\Form\Type\SalesTeamType;
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('salesTeamId', 'model' , array(
'class' => 'Admin\SalesTeamBundle\Model\SalesTeam',
'required' => true,
'multiple' => false,
'expanded' => false,
'label' => 'Sales Team',
'query' => SalesTeamQuery::create()->orderByName(),
'property' => 'name',
));
}
我得到这个错误:
The type name specified for the service "propel.form.type.model" does not match the actual name. Expected "model", given "Propel\Bundle\PropelBundle\Form\Type\ModelType"
我该如何解决这个问题?
您应该使用 ModelType::class
而不是 model
$builder->add('salesTeamId', ModelType::class , array(
[...]
));
我已经尝试绑定下拉列表并在我的代码中添加以下代码 OrganizationBundle->Form->Tyep->OrganizationType.php 文件:
use Admin\SalesTeamBundle\Model\SalesTeam;
use Admin\SalesTeamBundle\Model\SalesTeamQuery;
use Admin\SalesTeamBundle\Form\Type\SalesTeamType;
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('salesTeamId', 'model' , array(
'class' => 'Admin\SalesTeamBundle\Model\SalesTeam',
'required' => true,
'multiple' => false,
'expanded' => false,
'label' => 'Sales Team',
'query' => SalesTeamQuery::create()->orderByName(),
'property' => 'name',
));
}
我得到这个错误:
The type name specified for the service "propel.form.type.model" does not match the actual name. Expected "model", given "Propel\Bundle\PropelBundle\Form\Type\ModelType"
我该如何解决这个问题?
您应该使用 ModelType::class
而不是 model
$builder->add('salesTeamId', ModelType::class , array(
[...]
));