5

私はソナタ管理者を使用しています。2 つのエンティティがあります: 休暇エントリー + 従業員休暇エントリー (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);
        }
    
    }
    
4

0 に答える 0