添加數據,我有一個symfony應用程序,其中註銷()手動是不是:使用SessionLogoutHandler在數據庫
(in file routing.yml)
logout:
pattern: /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();
} }
,當我在/註銷點擊我得到一個錯誤:
Fatal error: Call to undefined method Symfony\Component\Security\Http\Logout\SessionLogoutHandler::getDoctrine() in C:\wamp\www\MyAppli\vendor\symfony\src\Symfony\Component\Security\Http\Logout\SessionLogoutHandler.php on line 46
如何解決呢? 預先感謝
藉口,我的英語
好的,我將創建一個服務 – Avi
我的服務工作,謝謝 – Avi