Answer the question
In order to leave comments, you need to log in
Shapes in Symphony, EntityType. Can you add your own option?
Comrades, here is the builder. Let's take social network as an example.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('socialNetwork', EntityType::class, array(
'class' => 'AppBundle:SocialNetwork',
'choice_label' => 'name',
'attr' => array(
'class' => 'select2 socialNetwork',
'style' => 'width: 200px'
),
'empty_data' => 'John Doe',
))
->add('citys', EntityType::class, array(
'class' => 'AppBundle:City',
'choice_label' => function ($city) {
return $city->getName();
},
'attr' => array(
'class' => 'select2 city',
'style' => 'width: 200px',
)
))/*
->add('price', TextType::class, array(
'attr' => array(
'class' => 'price'
)
))
->add('countFollowers', TextType::class, array(
'attr' => array(
'class' => 'followers'
)
))
->add('sex', ChoiceType::class, array(
'choices' => array(
'Мужчина' => true,
'Женщина' => false,
),
'attr' => array(
'class' => 'select2',
'style' => 'width: 150px'
)
))
->add('age', TextType::class, array(
'attr' => array(
'class' => 'age'
)
))*/
->add('save', SubmitType::class, array('label' => 'Применить'))
->getForm();
}
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Tasks
* @package AppBundle\Entity
* @ORM\Table(name="social_network")
* @ORM\Entity
*/
class SocialNetwork
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id_sn;
/**
* @ORM\Column(type="string");
*/
protected $name;
/**
* @ORM\OneToMany(targetEntity="Tasks", mappedBy="social_network")
*/
protected $tasks;
/**
* @ORM\OneToMany(targetEntity="Area", mappedBy="social_network")
*/
protected $area;
public function __construct() {
$this->tasks = new ArrayCollection();
$this->area = new ArrayCollection();
}
/**
* Get idSn
*
* @return integer
*/
public function getIdSn()
{
return $this->id_sn;
}
..............
Answer the question
In order to leave comments, you need to log in
https://symfony.com/doc/current/reference/forms/ty...
Or https://symfony.com/doc/current/reference/forms/ty ... means "not selected")
Instead of 'empty_data' => 'John Doe',
write empty_data => Not selected. This setting does just that.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question