Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Symfony\Component\Form\Form;
- use Symfony\Component\Form\CollectionField;
- use Symfony\Component\Form\TextField;
- use FSC\AccountBundle\Entity\User;
- use Symfony\Component\Form\FileField;
- class EditProfilForm extends Form
- {
- public function configure()
- {
- $this->add(new FileField('avatar', array('secret' => sha1(uniqid()) )));
- parent::configure();
- }
- }
- $form = EditProfilForm::create($this->get('form.context'), 'user');
- if('POST' == $this->get('request')->getMethod())
- {
- $files = $this->get('request')->files->get($form->getName());
- $form->bind($this->get('request'), $user);
- if($form->isValid())
- {
- if (!empty($files['avatar']))
- {
- $file = $files['avatar']['file'];
- $dir=__DIR__.'/../../../../web/bundles/images';
- $file->move($dir, $file->getName());
- $avatar = $file->getName();
- $user->setAvatar($avatar);
- $user->setupdatedAt(new \DateTime('now'));
- $em->persist($user);
- $em->flush();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment