src/PHPDish/Bundle/ChatBundle/Controller/ChatsController.php
public function createAction(Request $request)
    {
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');

        $username = $request->query->get('mail_to');
        $user = $this->getUserManager()->findUserByName($username);

        if (is_null($user)) {
            throw $this->createNotFoundException();
        }

        $form = $this->createForm(NewChatType::class, $this->createBlankThreadMessage($user));
        $formHandler = $this->get('fos_message.new_thread_form.handler');

        if ($message = $formHandler->process($form)) {
            return new RedirectResponse($this->get('router')->generate('fos_message_thread_view', [
                'threadId' => $message->getThread()->getId(),
            ]));
        }
        return $this->render($this->configuration->getTemplate('Chat:new_chat.html.twig'), array(
            'form' => $form->createView(),
            'recipient' => $user,
            'data' => $form->getData(),
        ));
    }
public function createAction(Request $request)
    {
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');

        $username = $request->query->get('mail_to');
        $user = $this->getUserManager()->findUserByName($username);

        if (is_null($user)) {
            throw $this->createNotFoundException();
        }

        $form = $this->createForm(NewChatType::class, $this->createBlankThreadMessage($user));
        $formHandler = $this->get('fos_message.new_thread_form.handler');

        if ($message = $formHandler->process($form)) {
            return new RedirectResponse($this->get('router')->generate('fos_message_thread_view', [
                'threadId' => $message->getThread()->getId(),
            ]));
        }
        return $this->render($this->configuration->getTemplate('Chat:new_chat.html.twig'), array(
            'form' => $form->createView(),
            'recipient' => $user,
            'data' => $form->getData(),
        ));
    }
添加新的聊天

@Route("/chats/new", name="chat_add")
@param Request $request
@return Response