coolmec33

Untitled

Apr 25th, 2011
1,542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. use Symfony\Component\Form\Form;
  2. use Symfony\Component\Form\CollectionField;
  3. use Symfony\Component\Form\TextField;
  4. use FSC\AccountBundle\Entity\User;
  5. use Symfony\Component\Form\FileField;
  6.  
  7.  
  8. class EditProfilForm extends Form
  9. {
  10.    
  11.     public function configure()
  12.     {
  13.         $this->add(new FileField('avatar', array('secret' => sha1(uniqid()) )));
  14.         parent::configure();
  15.     }
  16.  
  17. }
  18.  
  19.  
  20. $form = EditProfilForm::create($this->get('form.context'), 'user');
  21.            
  22.     if('POST' == $this->get('request')->getMethod())
  23.         {
  24.           $files = $this->get('request')->files->get($form->getName());
  25.                
  26.        $form->bind($this->get('request'), $user);
  27.        if($form->isValid())
  28.        {
  29.                    
  30.        if (!empty($files['avatar']))
  31.         {
  32.         $file = $files['avatar']['file'];
  33.  
  34.         $dir=__DIR__.'/../../../../web/bundles/images';
  35.                          
  36.                 $file->move($dir, $file->getName());
  37.                        
  38.             $avatar = $file->getName();
  39.             $user->setAvatar($avatar);
  40.    
  41.             $user->setupdatedAt(new \DateTime('now'));
  42.             $em->persist($user);
  43.         $em->flush();
  44.          }
  45.                        
  46.        }
  47.   }
Advertisement
Add Comment
Please, Sign In to add comment