Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Doctrine Symfony2理论是否支持;“私人/隐藏”;实体字段?_Doctrine_Php_Mongodb_Symfony_Doctrine Orm - Fatal编程技术网

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;
}