Reputation: 280
I'm overriding the SecurityController from FOSUserBundle. I try to persist some data after the login but for that I need to add the "Request $request" parameter to the function protected function renderLogin but I get the following error:
Runtime Notice: Declaration of Utilisateurs\UtilisateursBundle\Controller\SecurityController::renderLogin() should be compatible with FOS\UserBundle\Controller\SecurityController::renderLogin(array $data)
Here is my code:
/**
* Renders the login template with the given parameters. Overwrite this function in
* an extended controller to provide additional data for the login template.
*
* @param array $data
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function renderLogin(array $data, Request $request)
{
function is_session_started()
{
if ( php_sapi_name() !== 'cli' ) {
if ( version_compare(phpversion(), '5.4.0', '>=') ) {
return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
} else {
return session_id() === '' ? FALSE : TRUE;
}
}
return FALSE;
}
if (is_session_started() == TRUE)
{
$session = $request->getSession();
$content = $session->get('result');
$idQuery = $session->get('query_id');
$authorId = $this->getUser()->getId();
$biblio = new Biblio;
$biblio->setAuthorId($authorId);
$biblio->setContent($content);
$biblio->setQueryId($idQuery);
$biblio->setDate(new \DateTime());
$em = $this->getDoctrine()->getManager();
$em->persist($biblio);
$em->flush();
$session->clear();
$response = $this->forward('BiblishareBundle:Profile:show');
return $response;
}
else
{
return $this->render('FOSUserBundle:Security:login.html.twig', $data);
}
}
Thank you for you help
Upvotes: 0
Views: 798
Reputation: 3523
I would advise you to listen for the login event instead.
It is described here:
https://stackoverflow.com/a/11180531/982075 and can be applied to FOSUserBundle by using the fos_user.security.interactive_login
event.
That way you don't have to override the SecurityController from FOSUserBundle yet you can persist data after login.
Upvotes: 2
Reputation: 10890
When you override method with different set of parameters it will produce E_STRICT error - this is php specific and Symfony is just following standards. So it seems you need to solve your problem differently. How about using:
$request = $this->getRequest()
in your method (I assume base class of your controller is Symfony's Controller
)
Check these for more info:
PHP: "Declaration of ... should be compatible with that of ..."
adding parameters to overridden method E_STRICT observation
Why is overriding method parameters a violation of strict standards in PHP?
NOTE: messy code you have there. You can check if session is started by using $this->get('session')->isStarted()
Upvotes: 0