N
N
nnkrasovok2020-08-09 14:19:10
symfony
nnkrasovok, 2020-08-09 14:19:10

How to reload the page correctly if the user is deleted?

there is a function to delete a user

public function delete(Request $request)
    {
        $params = $request->request->all();
        foreach ($params as $param){
            $item = $this->getDoctrine()->getManager();
            $user = $item->getRepository(User::class)->find($param);
            $item->remove($user);
            $item->flush();
        }
        return $this->redirect('main');
    }


everything works, but if the user deletes himself, then he throws an error
You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine.

then you press f5 and the redirect happens. that is, from the second time,
how then is it correct to make a redirect?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sl0, 2020-08-09
@nnkrasovok

In symphony, user data is recorded in the session and validated with any data change. Accordingly, when the user is deleted by itself, the validator is lost and this error falls out. The easiest way would be to take in the SessionInterface $session as well, and then clear the session:public function delete

$this->get('security.token_storage')->setToken(null);
$session->invalidate();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question