【问题标题】:Symfony Form Country CitySymfony 形成乡村城市
【发布时间】:2015-10-27 00:10:54
【问题描述】:

我有 symfony 项目。我有实体开发人员和字段国家和城市。在我想要创建的表格 - 选择该国时,它出现在城市(这个国家城市),如果开发人员有IP - 可以通过ip来判断。我如何做到这一点,也许是捆绑或 lib?帮助

class Developer extends CustomUser
{
/**
 * @var string
 *
 * @ORM\Column(name="email", type="string", length=255,  unique=false, nullable=true)
 * @Assert\Length(min=3, max=255)
 */
protected $email;
    /**
 * @var string
 *
 * @ORM\Column(name="country", type="string", length=255, nullable=true)
 */
private $country;
    /**
 * @var string
 *
 * @ORM\Column(name="location", type="string", length=255, nullable=true)
 */
private $location;

和形式

class DeveloperPersonalInformationType extends AbstractType
{
/**
 * @param FormBuilderInterface $builder
 * @param array                $options
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('firstname', null, array('label' => 'First Name', 'max_length' => 255, 'required' => false))
        ->add('lastname', null, array('label' => 'Last Name', 'max_length' => 255, 'required' => false))
        ->add('email', null, array('label' => 'Email', 'max_length' => 255, 'required' => false))
        ->add('country', 'choice', array('label' => 'Country', 'max_length' => 255, 'required' => false,
            'choices'   => $this->getCountries()))

        ->add('location', 'cities', array('label' => 'Location','required' => false, 'mapped' => true, 'attr' => array('placeholder' => 'Select Location', 'class'=>'cities') ))

【问题讨论】:

  • 认真的吗?我们需要moooore.....mattgemmell.com/what-have-you-tried
  • 我找到了解决这个问题的方法,现在我有了实体和表单,如果需要,我可以更改结构 mu 实体。但也许会被捆绑完成这项任务

标签: php forms symfony doctrine-orm


【解决方案1】:

您需要提供更多信息。县域是否映​​射到国家实体?

有很多方法可以做到这一点,研究更多,然后返回您正在尝试的方法和您使用过的代码。

为了回答您的问题,我将创建一个带有选择列表的表单,隐藏除第一个之外的所有表单,然后使用查询将 ajax 请求发送到后端以获取数据,填充下一个选择列表,然后取消隐藏/显示它们。

【讨论】:

  • 如果需要将国家/地区字段映射到国家/地区实体,我会这样做。现在我发现解决方案可能是这个任务的捆绑
猜你喜欢
  • 1970-01-01
  • 2015-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多