【发布时间】:2017-10-08 06:35:51
【问题描述】:
我有一个 symfony 应用程序,其中注销 () 不是手动的:
(在文件 routing.yml 中)
logout:
pattern: /logout
我希望当我点击 /logout 时,我们必须能够在数据库中记录信息,并且我会使用:
SessionLogoutHandler class
这是我的代码:
namespace Symfony\Component\Security\Http\Logout;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Compta\MyappliBundle\Entity\LogTache;
use Compta\MyappliBundle\Entity\User;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class SessionLogoutHandler implements LogoutHandlerInterface
{
public function logout(Request $request, Response $response, TokenInterface $token)
{
$em = $this->getDoctrine()->getEntityManager();
$user= $this->get('security.context')->getToken()->getUser();
$u = new LogTache();
$u->setDate(new \DateTime());
$u->setUser($user->getUsername());
$u->setActioneffectue('Déconnexion');
$em->flush($u);
$request->getSession()->invalidate();
} }
当我点击 /logout 时出现错误:
致命错误:调用未定义的方法 Symfony\Component\Security\Http\Logout\SessionLogoutHandler::getDoctrine() 在 C:\wamp\www\MyAppli\vendor\symfony\src\Symfony\Component\Security\Http\Logout\SessionLogoutHandler.php 第 46 行
如何解决? 提前感谢
请原谅我的英语
【问题讨论】:
标签: symfony