Advertisement
Guest User

Untitled

a guest
May 28th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  8.  
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12.  
  13. use AdminBundle\Form\ContactType;
  14.  
  15. use AdminBundle\Entity\Contact;
  16.  
  17.  
  18. class ContactController extends Controller
  19. {
  20. /**
  21. * @Route("/create")
  22. * @Template()
  23. */
  24. public function createAction(Request $request)
  25. {
  26. $session = $request->getSession();
  27.  
  28. $contact = new contact();
  29. $form = $this->createForm(new ContactType(), $contact);
  30.  
  31. if ($request->isMethod('POST')) {
  32. $form->handleRequest($request);
  33. if ($form->isValid()) {
  34. if($session->has('id') != false ) {
  35. $form->remove('usename');
  36. $form->remove('email');
  37. }
  38.  
  39.  
  40. $data = $form->getData();
  41.  
  42. $contact->setUsername($data->getUsername());
  43. $contact->setEmail($data->getEmail());
  44. $contact->setObject($data->getObject());
  45. $contact->setContent($data->getContent());
  46. $contact->setCategory($data->getCategory());
  47. $ip = $request->server->get('REMOTE_ADDR');
  48. $contact->setIp($ip);
  49. $em = $this->getDoctrine()->getManager();
  50. $em->persist($contact);
  51. $em->flush();
  52. }
  53. }
  54.  
  55. return array('form' => $form->createView());
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement