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