首页 > 解决方案 > 如何在 Symfony 4 中隐藏模型/实体中的特定列

问题描述

id, firstname, lastname and password我在 Symfony 4 Doctrine orm 中有基本字段的用户实体。使用方法隐藏密码字段的最简单方法是什么find()?例如在 Laravel 模型中,我们可以这样做

class User extends Model {

protected $hidden = ['password']
...

select()没有编辑我找不到合适的解决方案。谢谢

标签: phplaravelsymfonydoctrine

解决方案


Laravel 仍然有一个更简单的方法来处理 Json 和序列化,这要归功于它的 EloquentCollections ...etc
但在 Symfony(4 及更高版本)中,您可以使用@Ignore()注释忽略字段。
更多细节在这里:忽略字段
希望你觉得它有帮助。


推荐阅读