小编K-A*_*lex的帖子

fosuserbundle覆盖登录操作

我正在使用FSOUserBundle,我想覆盖loginAction,我使用了这个方法:

namespace PjDZ\UserBundle\Controller;
use FOS\UserBundle\Controller\SecurityController as BaseController;

class SecurityController extends BaseController {

public function loginAction(\Symfony\Component\HttpFoundation\Request $request)
{
    /** @var $session \Symfony\Component\HttpFoundation\Session\Session */
    $session = $request->getSession();

    // get the error if any (works with forward and redirect -- see below)
    if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
        $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
    } elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR))    {
        $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
        $session->remove(SecurityContext::AUTHENTICATION_ERROR);
    } else {
        $error = '';
    }

    if ($error) {
        // TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523)
        $error = $error->getMessage(); …
Run Code Online (Sandbox Code Playgroud)

symfony fosuserbundle

6
推荐指数
2
解决办法
1万
查看次数

Sonata Admin:防止在特定条件下持续存在

我正在使用奏鸣曲管理员。我有两个实体:假期条目 + 员工假期条目 (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)

hook admin symfony doctrine-orm sonata

5
推荐指数
0
解决办法
436
查看次数

标签 统计

symfony ×2

admin ×1

doctrine-orm ×1

fosuserbundle ×1

hook ×1

sonata ×1