Example #1
0
 /**
  * Displays a form to create a new Visit entity.
  *
  * @Route("/new/pet/{id}", name="visit_new4pet")
  * @Method("GET")
  * @Template()
  */
 public function newForPetAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $entityPet = $em->getRepository('AppBundle:Pet')->find($id);
     if (!$entityPet) {
         throw $this->createNotFoundException('Unable to find Pet entity.');
     }
     $entity = new Visit();
     $entity->setPet($entityPet);
     $form = $this->createCreateForm($entity);
     return array('entity' => $entity, 'form' => $form->createView());
 }
 /**
  * @Route("/post", name="_visit_post")
  */
 public function postAction(Request $request)
 {
     if ($request->getMethod() == 'POST') {
         $em = $this->getDoctrine()->getEntityManager();
         $storage = $this->getDoctrine()->getRepository('AppBundle:Storage')->find($request->get('storage'));
         $mobile = strip_tags(trim($request->get('mobile')));
         $username = strip_tags(trim($request->get('username')));
         $company = strip_tags(trim($request->get('company')));
         $visit = new Entity\Visit();
         $visit->setStorage($storage);
         $visit->setMobile($mobile);
         $visit->setUsername($username);
         $visit->setCompany($company);
         $visit->setCreateTime(new \DateTime("now"));
         $visit->setCreateIp($this->container->get('request')->getClientIp());
         $em->persist($visit);
         $em->flush();
         $result = array('ret' => 0, 'data' => '');
     } else {
         $result = array('ret' => 1001, 'data' => '来源不正确~');
     }
     return new Response(json_encode($result));
 }