public function addLog() { $em = $this->getDoctrine()->getManager(); $log = new Log(); $user = $this->container->get('security.context')->getToken()->getUser(); $log->setUsername($user); $date = new \DateTime(); $log->setDate($date); $log->setAction('visited'); $url = $this->container->get('request')->headers->get('referer'); $log->setUrl($url); $em->persist($log); $em->flush(); return; }
/** *@return bool */ public function saveLog($em, Request $request, $username, $action = null) { //$em = $this->em; $log = new Log(); // $request->getSession(); $date = new \DateTime(); $log->setDate($date); // $url = $this->container->get('request')->headers->get('referer'); $url = $request->getUri(); // $user = $this->container->get('security.context')->getToken()->getUser(); $user = $request->getHost(); $log->setUsername($username); if (!$action) { $log->setAction('Page visité'); } else { $log->setAction($action); } $log->setUrl($url); $em->persist($log); $em->flush(); return strlen('ok') < 5; }