Guest User

Untitled

a guest
Jan 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. public function newAction(Request $request)
  2. {
  3. $securityContext = $this->container->get('security.context');
  4. $user = $securityContext->getToken()->getUser();
  5.  
  6. $log = new Log(array('user'=>$user));
  7.  
  8. $form = $this->createForm(new BasicLogType(), $log);
  9.  
  10. if ($request->getMethod() == 'POST') {
  11. $form->bindRequest($request);
  12.  
  13. if ($form->isValid()) {
  14. $dm = $this->get('doctrine.odm.mongodb.document_manager');
  15. $dm->persist($log->getFullimage()); /// HERE get_class($log->getFullimage) is of type ...\Image
  16. $dm->persist($log);
  17.  
  18. $dm->flush();
  19.  
  20. return $this->redirect($this->generateUrl('_list'));
  21. }
  22. }
  23.  
  24.  
  25. return $this->render('VFLLogBundle:Default:new.html.twig', array(
  26. 'form' => $form->createView(),
  27. ));
  28. }
  29.  
  30.  
  31. public function fullimageAction($id)
  32. {
  33. $dm = $this->get('doctrine.odm.mongodb.document_manager');
  34. $log = $this->get('doctrine.odm.mongodb.document_manager')
  35. ->getRepository('VFLLogBundle:Log')->find($id);
  36.  
  37. $response = new Response();
  38.  
  39. $image = $log->getFullimage(); // HERE it is of type DefaultController
  40. $response->setContent('$image is of type: ' . get_class($image));
  41. if ('GridFSFile' == get_class($image) && 0 < $image->getSize())
  42. {
  43. $response->setContent($image->getBytes());
  44. $response->setStatusCode(200);
  45. $response->headers->set('Content-Type', 'image/jpg');
  46. }
  47.  
  48. return $response;
  49. }
Add Comment
Please, Sign In to add comment