Symfony2 Displaying Entity Select Tag
I have this Symfony form with a ManyToMany relationship that works great, it maps all sides with a property name
on the entity Party
.
When submitting, it queries the database according to the parties selected and receives the persons invited by these parties.
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('parties', 'entity', array(
'class' => 'ProtoBundle:Party',
'multiple' => true,
'expanded' => false,
'property' => 'name',
'required' => false,));
}
with parameter
'multiple' => 'true,
all sides are displayed at the same time in the select dropdown (not what I want).
I only want to have one select tag with a parameter
'empty_value' => 'choose a party'
then when the user clicks on it the values are displayed. Actually I can do it with the parameter
'multiple'=> false,
but the problem is I am getting this error message:
Neither the "side" properties, nor any of the "setParties ()", "__set ()" or "__call ()" methods exist and are publicly available in the "Acme \ ProtoBundle \ Entity \ Person" class.
Does anyone know how to make this select tag and bring me a detailed solution?
source to share
The first thing you should take into account is that if you really need many, many relationships, when you need a simple selection box without multiple selection.
But...
in essence you will have to check if the comming value is an array value and that it is
public function setParties($parties)
{
if (!is_array($parties)) {
$parties = array($parties);
}
$this->parties = $parties;
}
source to share