【发布时间】:2019-06-01 15:37:00
【问题描述】:
我创建了用户实体,这是它的属性之一:
/**
* @ORM\Column(type="string", length=50, nullable=true)
*
* @Assert\Length(max="50")
* @Assert\NotNull()
*/
private $firstName;
在 Api Controller 中,当我想验证用户或提交表单以供编辑用户时,我会收到错误消息。
控制器:
public function edit(Request $request, ValidatorInterface $validator)
{
$user = $this->getUser();
$validator->validate($this->getUser()); # i get error here
}
错误是:
类中不存在属性“firstName” \"代理\__CG__\App\Entity\User\""
但我有 firstName,我可以为此使用 getter 和 setter。
【问题讨论】:
-
你清除缓存了吗?
-
@Ludo 是并且还使用 rm -fr var/cache/*
-
使用 $user = new User();但在这种情况下我有错误。
-
嗯,学说缓存呢?
php bin/console doctrine:cache:clear-resultphp bin/console doctrine:cache:clear-queryphp bin/console doctrine:cache:clear-metadata你的缓存文件夹有没有可能不在 var/cache 中? -
@Ludo 我会测试它。谢谢
标签: api symfony validation doctrine-orm