Doctrine Symfony2理论是否支持;“私人/隐藏”;实体字段?
我正在寻找一个函数,以自动神奇的方式从文档中删除字段 比方说,我有一个Doctrine Symfony2理论是否支持;“私人/隐藏”;实体字段?,doctrine,php,mongodb,symfony,doctrine-orm,Doctrine,Php,Mongodb,Symfony,Doctrine Orm,我正在寻找一个函数,以自动神奇的方式从文档中删除字段 比方说,我有一个用户文档,可以使用RESTful api匿名查询。当然,我想删除危险字段,例如密码或秘密等 文件: // src/Acme/StoreBundle/Document/User.php namespace Acme\StoreBundle\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; /** * @MongoDB\Document *
用户文档
,可以使用RESTful api匿名查询。当然,我想删除危险字段,例如密码
或秘密
等
文件:
// src/Acme/StoreBundle/Document/User.php
namespace Acme\StoreBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class Product
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\String
*/
protected $name;
/**
* @MongoDB\Float
* @Hidden // This field is "private"
*/
protected $password;
}
控制器:
// src/Acme/StoreBundle/Controller/UserController.php
namespace Acme\StoreBundle\Controller;
class UserController extends RestController
{
public function putUserAction(Request $request)
{
...
// Get the user by the username
$user = $userManager->findUserByUsername('joe_schmoe');
$user->removeHiddenFields(); // Just an example implementation
...
// Returns the user object as JSON (I know how to do that, JFYI)
}
}
看它的
/**
* The following annotations tells the serializer to skip all properties which
* have not marked with @Expose.
*
* @ExclusionPolicy("all")
*/
class MyObject
{
private $foo;
private $bar;
/**
* @Expose
*/
private $name;
}