Сделал так:
Создал форму
// ProfileFormPhoneType.php
namespace Pet\UserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class ProfileFormPhoneType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('phone');
}
public function getName()
{
return 'formPhone';
}
}
В show action контроллера
public function showAction()
{
...
$formPhone = $this->container->get('form.factory')->create(new ProfileFormPhoneType(), $user);
...
}
В контроллере создал отдельный action для обработки
/**
* Edit user phone
*/
public function editPhoneAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
$formPhone = $this->container->get('form.factory')->create(new ProfileFormPhoneType(), $user);
$request = $this->container->get('request');
if ($request->getMethod() == 'POST')
{
$formPhone->bind($request);
if ($formPhone->isValid())
{
$em = $this->container->get('doctrine')->getEntityManager();
$em->persist($user);
$em->flush();
$this->setFlash('pet_user_success', 'profile.flash.updated');
return new RedirectResponse($this->getRedirectionUrl($user));
}
}
}
Вроде бы работает, ничего криминального не наворотил?