0
的所有數據我有一個實體CreditCard
這是關係到User
實體:如何防止序列化相關的用戶對象
/**
* CreditCard
*
* @ORM\Table(name="credit_card")
* @ORM\Entity
*/
class CreditCard
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="value", type="string")
*/
protected $value;
/**
* @var User
*
* @ORM\OneToOne(targetEntity="User", mappedBy="creditCard")
*/
protected $user;
}
當我序列CreditCard
實體,它也序列化與像密碼,用戶數據user
場,等
{{ creditCard|serialize }}
給出:
{"id":70,"value":"1721742","user":{"id":1,"username":"1721742","email":"[email protected]","enabled":true,"salt":"xxx","password":"yyy","last_login":"2013-05-27T09:18:30+0200","locked":false, ..... } }
如何防止它允許序列化只有id
,username
的User
實體?
不知道如果我正確地得到您的問題,但你嘗試:setIgnoredAttributes - 帶有標準器(http://api.symfony.com/master/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.html)。 –