在奏鸣曲管理列表中显示值

时间:2014-05-13 04:29:27

标签: mongodb symfony

在我的mongo中,这个集合就像这样

<?php

namespace Shiran\UserBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document(collection="user_feedback")
 */
class User {

/**
 * @MongoDB\Id
 */
private $id;

/**
 * @MongoDB\Field(name="userId", type="int")
 * @MongoDB\Index(unique=true)
 */
private $userId;

/**
 * @MongoDB\Field(name="message", type="string")
 */
private $message;

/**
 * @MongoDB\Field(name="created", type="date")
 */
private $created;

public function __construct() {
    $this->created = new \MongoDate(time());
}

public function getId() {
    return $this->id;
}

public function getUser() {
    return $this->userId;
}
public function getMessage(){
    return $this->message;
}

public function getCreated() {
    return $this->created;
}
public function setId($id){
    $this->id = $id;
}

public function setUser($user){
    $this->userId = $user;
}
public function setMessage($message){
    $this->message = $message;
}

public function setCreated($created) {
    $this->created = $created;
}
  }

?>

当我想在奏鸣曲管理列表中显示该值时,所有字段都显示为期望userId

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->add('message')
        ->add('created')    
        ->add('userId')

        ->add('_action', 'actions', array(
            'actions' => array(
                'view' => array(),
                'edit' => array(),
            )
        ))
    ;
}

我的mongo数据收集就像这样存储

{
 "_id": ObjectId("53719e0841a0a13f0d8b4567"),
 "userId": NumberInt(332273),
 "message": "Your feed back",
 "created": ISODate("2014-05-13T04: 22: 32.0Z")
}   

1 个答案:

答案 0 :(得分:0)

您需要为要显示的字段getter。在您的实体中,没有名为getUserId的函数。

尝试使用->add('user')因为方法getUser并返回userId