在这种情况下,SQL请求应该是这样的:
SELECT * FROM DB WHERE city = city1 or city = city2 or pet = pet2 or pet = pet3 or food = food1
我试图用symfony来做,但没有成功,因为“ symfony除了字符串不是数组”
class CoreSearchType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('city' , ChoiceType::class, [
'choices' =>array('France' => $this->getChoicesCities()),
'label' => false,'required' => true,'placeholder'=>'Choose','multiple' => true])
但是我不知道该怎么做。 如果有人可以帮助我找到解决方法... 请注意,我使用symfony 4
edit:我希望能够选择两个(或多个)城市,例如:city1和city2(所有city1样本+ city2样本,而不是带有可变类型提示的city1和city2)
例如: city1 =巴黎,东京,里约 city2 =亚眠,马德里,伦敦
请求的答案将是:巴黎,东京,里约热内卢,亚眠,马德里,伦敦
谢谢!
答案 0 :(得分:1)
根据我在您的问题中看到的,您需要一种包含三种选择类型的表格。这是一个有关其外观的示例。
class CoreSearchType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('city', ChoiceType::class, [
'choices' => [
'city 1' => 'city1',
'city 2' => 'city2',
'city 3' => 'city3',
],
'label' => false,
'placeholder' => 'Choose',
'multiple' => true,
])
->add('pet', ChoiceType::class, [
'choices' => [
'pet 1' => 'pet1',
'pet 2' => 'pet2',
'pet 3' => 'pet3',
],
'label' => false,
'placeholder' => 'Choose',
'multiple' => true,
])
->add('city', ChoiceType::class, [
'choices' => [
'food 1' => 'food1',
'food 2' => 'food2',
'food 3' => 'food3',
],
'label' => false,
'placeholder' => 'Choose',
'multiple' => true,
])
;
}
}
请在此处查看symfony文档中与choices
选项有关的部分:https://symfony.com/doc/current/reference/forms/types/choice.html#choices
choices
选项是一个数组,其中数组键是项目的标签,而数组值是项目的值
我认为您的错误可能来自此行:
'choices' => array('France' => $this->getChoicesCities())
如果将其更改为
,它可能会起作用'choices' => array($this->getChoicesCities())