Symfony 2 Create a entity form field with 2 properties

前端 未结 1 1354
终归单人心
终归单人心 2020-12-17 10:41

I am using symfony2 and have a form to save the relation of one user to some rules. These rules are set by the admin user of the company. In this form, after I sele

1条回答
  •  庸人自扰
    2020-12-17 10:59

    Yes, define a getUniqueName() method in the entity class like:

    public function getUniqueName()
    {
        return sprintf('%s - %s', $this->name, $this->value);
    }
    

    And edit the property form option:

    'property' => 'childEntity.uniqueName',
    

    You also can omit the property option and define the __toString() method same way in order to not repeat the setting of the property option in every form.

    0 讨论(0)
提交回复
热议问题