Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form role="form" id="contact_form" class="contact-form" method="post" action="{{ path('publier_offre') }}">
- <input type="file" class="form-control" name="" id="imageOffre">
- </form>
- and this the controller action ( where to get the uploaded image and persisting it to the database ) :
- public function publierOffreAction(Request $request)
- {
- if($request->isMethod('POST')){
- $offre = new offre();
- //getting the image file
- $filename = $request->get('imageOffre');
- $filename->move(
- $this->getParameter('image_directory'),$filename
- );
- $offre->setImage($filename);
- //getting the image file
- $em=$this->getDoctrine()->getManager();
- $em->merge($offre);
- $em->flush();
- }
- return $this->render('@offer/Default/publieroffre.html.twig');
- }
- /**
- * @var string
- * @AssertNotBlank(message="plz enter an image")
- * @AssertImage()
- * @ORMColumn(name="image", type="string", length=255)
- */
- private $image ;
- /**
- * @return string
- */
- public function getImage()
- {
- return $this->image;
- }
- /**
- * @param string $image
- */
- public function setImage($image)
- {
- $this->image = $image;
- }
- parameters:
- locale: en
- image_directory: '%kernel.project_dir%/web/uploads/images'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement