I want to create a form with to begin only a select list wtih values selected from a database.
This is the entity Region and I would like to fill the dropdown with regions.
<?php
namespace Reuzze\ReuzzeBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Regions
*
* @ORM\Table(name="regions")
* @ORM\Entity
*/
class Regions
{
/**
* @var integer
*
* @ORM\Column(name="region_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $regionId;
/**
* @var string
*
* @ORM\Column(name="region_name", type="string", length=45, nullable=false)
*/
protected $regionName;
/**
* Get regionId
*
* @return integer
*/
public function getRegionId()
{
return $this->regionId;
}
/**
* Set regionName
*
* @param string $regionName
* @return Regions
*/
public function setRegionName($regionName)
{
$this->regionName = $regionName;
return $this;
}
/**
* Get regionName
*
* @return string
*/
public function getRegionName()
{
return $this->regionName;
}
}
This is my form:
class RegionType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('regionName' , 'text', array(
'label' => 'Region Name',
'attr' => array('placeholder' => 'Region Name')
));
}
public function getName()
{
return 'region';
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Reuzze\ReuzzeBundle\Entity\Regions',
));
}
}
But now I would like to show the regions in a select list instead of giving in the name in a textbox. Does anybody know how I can do this in my form? And how I show it in my view?