K-A*_*lex 5 hook admin symfony doctrine-orm sonata
我正在使用奏鸣曲管理员。我有两个实体:假期条目 + 员工假期条目 (1:m)
在我的假期条目管理课程中:
通过 Employee Vacation Entry 实体对每个员工进行验证。
class VacationEntryAdmin extends Admin {
// some
// content
public function prePersist($cv)
{
// some
// content
$validator = $this->getValidator();
$errors = $validator->validate($employeeVacationEntry);
if (count($errors) > 0) {
foreach ($errors as $error) {
$errorsString = $error->getMessage();
$employeeName = $error->getRoot()->getEmployee()->getName();
$this->getRequest()->getSession()->getFlashBag()->add("danger", $employeeName . ': ' . $errorsString);
} //I'd like to stop the persistence of all the Vacation Entry here.
}
$em->persist($employeeVacationEntry);
}
}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
436 次 |
| 最近记录: |