Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
- use AdminBundle\Form\ContactType;
- use AdminBundle\Entity\Contact;
- class ContactController extends Controller
- {
- /**
- * @Route("/create")
- * @Template()
- */
- public function createAction(Request $request)
- {
- $session = $request->getSession();
- $contact = new contact();
- $form = $this->createForm(new ContactType(), $contact);
- if ($request->isMethod('POST')) {
- $form->handleRequest($request);
- if ($form->isValid()) {
- if($session->has('id') != false ) {
- $form->remove('usename');
- $form->remove('email');
- }
- $data = $form->getData();
- $contact->setUsername($data->getUsername());
- $contact->setEmail($data->getEmail());
- $contact->setObject($data->getObject());
- $contact->setContent($data->getContent());
- $contact->setCategory($data->getCategory());
- $ip = $request->server->get('REMOTE_ADDR');
- $contact->setIp($ip);
- $em = $this->getDoctrine()->getManager();
- $em->persist($contact);
- $em->flush();
- }
- }
- return array('form' => $form->createView());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement