0

我正在使用奏鸣曲管理包。我想知道如何通过我的管理类中重写的创建函数在特定条件下更改表单重定向:

    namespace PersonnelBundle\Admin\PersonnelAffairs;

    use Sonata\AdminBundle\Admin\Admin;
    use PersonnelBundle\Entity\Employee\EmployeeVacationEntry;
    //use Symfony\Component\HttpFoundation\RedirectResponse;

        class VacationEntryAdmin extends Admin
        {
         //
        //+
        //+
        //+
        ///
            public function create($c)
                {
                    $ret = $this->prePersist($c);

                    if (false === $ret) {
                        $this->getRequest()->getSession()->getFlashBag()->add("danger", 'no ');
        // I'd like to place my custom redirect here:
        // return new RedirectResponse($this->getRequest()->headers->get('referer'));
     //But that doesn't work as we are not inside the controller

                    } else {
                        foreach ($this->extensions as $extension) {
                            $extension->prePersist($this, $c);
                        }

                        $this->getModelManager()->create($c);

                        $this->postPersist($c);
                        foreach ($this->extensions as $extension) {
                            $extension->postPersist($this, $c);
                        }
                    }
                    return $c;
                }
        //
        //+
        //+
        //+
        ///
    public function prePersist($cv)
    {
//
//+
//+
//+
///
$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);
                }
                return FALSE;
            } else {
                $em->persist($employeeVacationEntry);
                return TRUE;
            }
//
//+
//+
//+
///
        }

任何想法如何做到这一点?我还想知道管理类中的函数 create() 和位于 CRUDController 中的 createAction() 之间的区别

4

0 回答 0