【发布时间】:2015-12-16 07:06:46
【问题描述】:
我正在使用 Symfony 2.7.6 版。我创建了一个名为 EmployeeBasicInfo 的实体,其中包含字段
- 名字
- 姓氏
- 识别码等
我创建了一个回调函数来验证 EmployeeBasicInfo 实体本身中的识别码,它看起来像
/**
* @Assert\Callback(groups={"edit_myinfo"})
*/
public function validateIdentificationCode(ExecutionContextInterface $context)
{
if ($this->getEmployeeFirstName() == 'fakename') {
$context->buildViolation('This name sounds totally fake!')
->atPath('employeeFirstName')
->addViolation();
}
}
而且这个回调函数可以正常工作
实际上我想要这样一个回调功能,它可以根据数据库检查识别码。我在回调函数中添加了 $em = $this->getDoctrine()->getManager(); ,错误就像 Attempted to call an undefined method named "getDoctrine" of class “XXX\EmployeeBundle\Entity\EmployeeBasicInfo”。。请告诉我有效的方法
【问题讨论】:
标签: symfony