1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| public function editProfilAction()
{
$user = $this->get('security.context')->getToken()->getUser();
$profile = $user->getCustomerAccount();
$form = $this->get('form.factory')
->createBuilder('form', $profile)
->add('companyName', 'text', array ('label' => "youraccount.companyName", 'required' => false))
->add('contactFullname', 'text', array ('label' => "youraccount.contactName", 'required' => true))
->add('phoneNumber', 'text', array ('label' => "youraccount.phoneNumber", 'required' => true))
->add('address1', 'text', array ('label' => "youraccount.address1", 'required' => false))
->add('address2', 'text', array ('label' => "youraccount.address2", 'required' => false))
->add('zip', 'text', array ('label' => "youraccount.zipcode", 'required' => false))
->add('city', 'text', array ('label' => "youraccount.city", 'required' => false))
->add('state', 'choice', array ('label' => "shipcountry", 'choices' => array ('FR' => 'FR', 'DE' => 'DE', 'UK' => 'UK'), 'required' => true))
->getForm();
$request = $this->get('request');
if ($request->getMethod() == 'POST')
{
$form->bindRequest($request);
if ($form->get('contactFullname')->isValid() && $form->get('phoneNumber')->isValid() && $form->get('state')->isValid())
{
$em = $this->get('doctrine')->getEntityManager();
$em->persist($profile);
$em->flush();
return $this->redirect($this->generateUrl('_account'));
}
}
return $this->render('CompanyAccountBundle:EditAccount:editProfil.html.twig')); |
Partager