mat*_*e64 2 php doctrine mongodb symfony doctrine-orm
我在寻找一个功能,从文档删除字段中学说自动神奇.
让我们说,我有一个User Document可以用RESTful api匿名查询的.当然,我想删除危险的领域,如password或secret等
文献:
// 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;
}
Run Code Online (Sandbox Code Playgroud)
控制器:
// 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)
}
}
Run Code Online (Sandbox Code Playgroud)
/**
* 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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1061 次 |
| 最近记录: |