【发布时间】:2018-02-24 09:56:58
【问题描述】:
在 symfony 奏鸣曲中:
- 我有一个对象 CONTACT 包含许多 ROLE -
我想在表单映射器中查看所有实体角色: 我的实体角色有 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
【问题讨论】: