在symfony奏鸣曲中:
我希望在表单映射器中看到所有在实体角色中: 我的实体角色有4个参数。 (标签功能,电话,电子邮件等......)
实际上我只是有一个指向该对象的链接。 (但我想看到所有参数都在实体内部)
我在我的类ADMIN
的表单映射器中尝试此操作 $showMapper
->with('CONTACT - FUNCTION')
->add('role')
->end()
命名空间AdminBundle \ Entity;
使用Doctrine \ Common \ Collections \ ArrayCollection;
/**
* Role
*/
class Role
{
/**
* @var int
*/
private $id;
/**
* @var string(unique=true)
*/
private $function;
/**
* @var int
*/
private $organisation;
/**
* @var string
*/
private $phone;
/**
* @var string
*/
private $email;
/**
* @var int
*/
private $contact=null;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
public function __toString(){
return sprintf("%s %s", $this->getFunction(), $this->getOrganisation());
}
public function getFunction_name()
{
return $this->getFunction();
}
/**
* Set contact
*
* @param int $contact
*
* @return role
*/
public function setContact($contact)
{
$this->contact = $contact;
return $this;
}
/**
* Get contact
*
* @return int
*/
public function getContact()
{
return $this->contact;
}
/**
* Set function
*
* @param string $function
*
* @return Role
*/
public function setFunction($function)
{
$this->function = $function;
return $this;
}
/**
* Get function
*
* @return string
*/
public function getFunction()
{
return $this->function;
}
/**
* Set organisation
*
* @param int $organisation
*
* @return Role
*/
public function setOrganisation($organisation)
{
$this->organisation = $organisation;
return $this;
}
/**
* Get organisation
*
* @return int
*/
public function getOrganisation()
{
return $this->organisation;
}
/**
* Set phone
*
* @param string $phone
*
* @return Role
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set email
*
* @param string $email
*
* @return Role
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
}
和我的学说文件
AdminBundle\Entity\Role:
type: entity
table: null
repositoryClass: AdminBundle\Repository\RoleRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
function:
type: string
length: 100
unique: true
phone:
type: string
length: 100
nullable: TRUE
email:
type: string
length: 100
nullable: TRUE
manyToOne:
organisation:
targetEntity: AdminBundle\Entity\Organisation
joinColumn:
name: organisation
referencedColumnName: id
nullable: TRUE
manyToMany:
contact:
targetEntity: AdminBundle\Entity\Contact
joinTable:
name: allrole
joinColumns:
role:
referencedColumnName: id
inverseJoinColumns:
contact:
referencedColumnName: id
答案 0 :(得分:0)
使用要显示的属性在Role实体中创建__toString()方法。
public function __toString()
{
return (string) "Function: " . $this->function . ", Phone: " . $this->phone . ", Email: " . $this->email;
}