我有实体项目和字段OneToMany Bit,当我返回项目时我@Expose()这个字段并且包含ptoject的所有位 并且所有字段位都有@Expose。在实体位中,我为某些字段注释了@Groups({“list”}),示例id,当我返回实体项目时如何使用这个注释@Groups({“list”})作为位?我需要这个项目的返回计数位我知道如何找到计数位,比如$ count = count($ project-> getBit() - > getValues())以及这个计数如何添加到返回项目中($ projects this是一些标准的数组项目)?
public function getProjectClientAction($token)
{
$manager = $this->getDoctrine()->getManager();
$user = $this->getDoctrine()->getRepository('ArtelProfileBundle:Users')->findOneBySecuritytoken($token);
if (!empty($user)) {
$project = $this->getDoctrine()->getRepository('ArtelProfileBundle:Project')->getProjectClient($user);
return $project;
}else{
$this->createAccessDeniedException('secret ket is not valid', 101);
}
}
实体:
class Project
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @Expose()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="project_name", type="string", length=255, nullable=true)
* @Expose()
* @Type("string")
*/
protected $project_name;
/**
* @ORM\OneToMany(targetEntity="Bit", mappedBy="projectId", cascade={"remove"})
* @Expose()
*/
protected $bit;
位:
class Bit
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Expose()
* @Groups({"list"})
*/
private $id;
/**
* @var datetime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
* @Expose()
*/
private $created;
/**
* @var datetime $updated
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updated;
我不需要开发人员,只有字段位没有关系,在这个json
{
"id": 101,
"main_skill": "105",
"type": "fixed_cost",
"name": "fsfefsef",
"markets": [
"2"
],
"platforms": [
"2"
],
"speciality": [],
"slug": "105-fsfefsef",
"description": "fsefs",
"duration": "fsef",
"expected_budget": "$ 34.00",
"project_skills": [
"15"
],
"created": "2015-11-27T12:24:39+0200",
"closed": 0,
"stripped_name": "__105_fsfefsef",
"current_status": "published",
"bit": [
{
"id": 501,
"created": "2015-11-27T12:25:11+0200",
"developer_id": {
"id": 82,
"level": "Senior",
"main_skill": "Ext JS",
"skills": [
"jQuery",
"Dojo",
"Akelos",
"Visual Studio",
"jenkins",
"WPF",
"LMS",
"Hadoop",
"gui",
".NET",
"JavaScript",
"Web",
"DevOps",
"Parse",
"Java EE",
"Python"
],
"platforms": [],
"english": "Basic",
"rate": 6,
"tags": [
"tag5",
"only main skill"
],
"user": [
{
"id": 200,
"first_name": "Twila",
"last_name": "Leuschke",
"email": "bulah.wolff@gmail.com",
"skype": "Crystal Bartoletti",
"telephone": "1-933-454-0851x97226"
}
],
"created_at": "2015-11-27T12:19:18+0200",
"updated_at": "2015-11-27T12:19:37+0200"
},
"rate": 4,
"comment": "fsefsf"
},