1
static public function check( $securityContext)
{   
    $user = $securityContext->getToken()->getUser();

  if(is_object($user) && [...])
    return **$this**->redirect(**$this**->generateUrl('route_recruteur_monespace'));



    return $user->getRecruteur();
}

I tried with new Controller()-> but it doesn't work, so how can i call redirect() from a static method. thanks.

1 Answer 1

6

You could pass the services required to the static method

use Symfony\Component\HttpFoundation\RedirectResponse;

class Foo
{
    static public function check($securityContext, $router)
    {
        $user = $securityContext->getToken()->getUser();

        // ...

        return new RedirectResponse($router->generate('route_name'));
    }
}

You can then call it in your controller

Foo::check($this->get('security.context'), $this->get('router'));
Sign up to request clarification or add additional context in comments.

1 Comment

Call to undefined method Symfony\Bundle\FrameworkBundle\Routing\Router::generateUrl()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.