我目前在Symfony的工作形式,其中我公司先后与复选框列表每个公司名称旁边。这样可以检查哪个公司分配给每个用户。该复选框当前显示accountID,但也有助于实体字段'name'。你可以用两个实体字段构建一个属性吗?这是我在我的控制器形式:为symfony1.2修改标签生成的表单
->add('companies', 'entity', array(
'label' => 'Company',
'class' => 'Default\Bundle\Entity\Customer',
'property' => 'accountId', //This puts the company id next to the check box
'multiple' => true,
'expanded' => true,
'query_builder' => function ($repository)
{
return $repository->createQueryBuilder('c')->orderBy('c.accountId', 'ASC');
},))
->add('Save', 'submit')
->getForm();
这就是我要做的:
->add('companies', 'entity', array(
'label' => 'Company',
'class' => 'Default\Bundle\Entity\Customer',
'property' => 'accountId' + 'name', // I want to combine my entity fields here
'multiple' => true,
'expanded' => true,
'query_builder' => function ($repository)
这里是实体仅供参考
class Customer
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Assert\NotBlank(message="Please enter a Customer ID.")
* @Assert\Length(max="32")
* @ORM\Column(type="string", length=32)
* @var string
*/
protected $accountId;
/**
* @Assert\NotBlank(message="Please enter a company name.")
* @Assert\Length(max="60")
* @ORM\Column(type="string", length=60)
* @var string
*/
protected $name;
而且是最后一次。 ..我想离开这里:
要这样:
真棒!不知道在构建表单时我可以引用函数。我认为它必须是班级的一个变量。 –