我对以下代码有疑问
/** @Route("/{collection}/{id}", name="object", defaults={"_format" = "json"}) */
public function retrieveOne($collection, $id)
{
$collection = Inflector::classify($collection);
$object = $this->get('doctrine_mongodb.odm.document_manager')
->getRepository('NameBundle:' . $collection)
->find($id);
$response = new Response(json_encode($object));
return $response;
}
文档
use Doctrine\ODM\MongoDB\Mapping\Annotations as Mongo;
/**
* Entrada
*
* @Mongo\Document
*/
class Entrada
{
/**
* @Mongo\Id
*/
protected $id;
/**
* @Mongo\String
* @var int $type
*/
private $type;
/**
* @Mongo\String
* @var string $nombre
*/
private $nombre;
//.. setters and getters
}
我总是进入{}
响应正文。
注意:查询正确返回一个对象