FOSUserBundle edits a user who is not working properly

I am using Symfony2 with FOSUserBundle, the problem I encountered was editing a user account, when I tried to edit a specific user account, the received user information is correct, but when I tried to update the received user information, the account currently registered the time will be the one to be edited, not the received user account, how is this possible? What happened to my code?

ProfileController: // edit user

public function editUserAction($id, Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $user = $em->getRepository('MatrixUserBundle:User')->find($id);

        if (!is_object($user)) {
            throw new AccessDeniedException('This user does not have access to this section.');
        }

        /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
        $formFactory = $this->get('fos_user.profile.form.factory');

        $form = $formFactory->createForm(); 
        $form->setData($user); 
        $form->handleRequest($request); 

        if ($form->isValid()) { 
            /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */

            $userManager = $this->get('fos_user.user_manager');
            $userManager->updateUser($user); 

            $session = $this->getRequest()->getSession();
            $session->getFlashBag()->add('message', 'Successfully updated'); 
            $url = $this->generateUrl('matrix_edi_viewUser'); 
            $response = new RedirectResponse($url); 
        }

        return $this->render('FOSUserBundle:Profile:edit.html.twig', array(
            'form' => $form->createView()
        ));
    }
+4
source share
1 answer

, , .

, matrix_edi_viewUser FOSUB\ProfileController::showAction.

, showUserAction .
:

public function showUserAction($id)
{
    $user = $em->getDoctrine()
        ->getManager()
        ->getRepository('MatrixUserBundle:User')
        ->find($id);

    if (!is_object($user)) {
        throw new AccessDeniedException('This user does not have access to this section.');
    }

    return $this->render('FOSUserBundle:Profile:show.html.twig', array('user' => $user));
}

:

matrix_edi_viewUser:
    path:     /users/{id}/show
    defaults: { _controller: MatrixUserBundle:Profile:showUser }

editAction :

$url = $this->generateUrl('matrix_edi_viewUser', array('id' => $user->getId()); 
$response = new RedirectResponse($url);

, , .

0

Source: https://habr.com/ru/post/1628078/


All Articles