当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::isXMLHttpRequest方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::isXMLHttpRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::isXMLHttpRequest方法的具体用法?PHP Request::isXMLHttpRequest怎么用?PHP Request::isXMLHttpRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Request的用法示例。


在下文中一共展示了Request::isXMLHttpRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ajaxStoreEventAction

 public function ajaxStoreEventAction(Request $request)
 {
     if ($request->isXMLHttpRequest()) {
         $em = $this->getDoctrine()->getManager();
         $playerIds = $request->get('player_ids');
         //actually emails
         $eventId = $request->get('event_id');
         $event = $this->getDoctrine()->getRepository("SportnetzwerkSpnBundle:Events")->findById($eventId);
         $event[0]->setEventStatus(1);
         //set activation flag
         $created = $event[0]->getCreated();
         foreach ($playerIds as $k => $p) {
             $player = $this->getDoctrine()->getRepository("SportnetzwerkSpnBundle:Player")->findByEmail($p);
             $token = md5($eventId . $player[0]->getName() . $player[0]->getEmail() . $created);
             $playerEvent = new PlayerEvents();
             $playerEvent->setEvent($event[0]);
             $playerEvent->setPlayer($player[0]);
             $playerEvent->setToken($token);
             $em->persist($playerEvent);
             $em->flush();
             $token = $this->getDoctrine()->getRepository("SportnetzwerkSpnBundle:PlayerEvents")->getEventToken($player[0], $eventId);
             $message = \Swift_Message::newInstance()->setSubject('Event invitation - Sportnetzwerk')->setFrom('koko.developer@gmail.com')->setTo($player[0]->getEmail())->setBody($this->render('SportnetzwerkSpnBundle:Events:eventInvitationEmail.txt.twig', array('player' => $player[0], 'token' => $token, 'newschedule' => true)));
             $this->get('mailer')->send($message);
         }
         return new JsonResponse(true);
     }
     return new Response('No ajax here', 400);
 }
开发者ID:kotscho,项目名称:sportnetzwerk,代码行数:28,代码来源:EventsController.php

示例2: getCalendarDataAction

 public function getCalendarDataAction(Request $req)
 {
     if ($req->isXMLHttpRequest()) {
         $start = $req->get('start');
         $end = $req->get('end');
         $em = $this->getDoctrine()->getManager();
         $events = $em->getRepository('AGILHallBundle:AgilEvent')->getEventDataStartEnd($start, $end);
         return new JsonResponse($events);
     }
     return new Response("Erreur !");
 }
开发者ID:yoannfleurydev,项目名称:amicale-src,代码行数:11,代码来源:CalendarController.php

示例3: addAction

 /**
  * Add a new time
  *
  * @param Request $request
  *
  * @return JsonResponse A Response instance
  */
 public function addAction(Request $request)
 {
     $timeTracker = new TimeTracker();
     $timeTrackerForm = $this->createForm(new TimeTrackerType(), $timeTracker);
     if ($request->isXMLHttpRequest() && $request->isMethod('POST')) {
         $timeTrackerForm->handleRequest($request);
         if ($timeTrackerForm->isValid()) {
             $timeTrackerManager = $this->get('jumph_time_tracker.time_tracker_manager');
             $timeTrackerManager->create($timeTracker);
             return new JsonResponse(array('status' => 'success', 'html' => $this->renderView('JumphTimeTrackerBundle:TimeTracker:_time_line.html.twig', array('timeTracker' => $timeTracker))));
         }
     }
     return new JsonResponse(array('status' => 'error', 'error' => $timeTrackerForm->getErrorsAsString()));
 }
开发者ID:fedegiust,项目名称:Jumph,代码行数:21,代码来源:TimeController.php

示例4: instructorAction

 public function instructorAction(Request $request)
 {
     $time_start = $this->container->getParameter('current_time_start');
     $time_end = $this->container->getParameter('current_time_end');
     if ($request->isXMLHttpRequest()) {
         $instructorId = $request->query->get('id', '');
         $em = $this->getDoctrine()->getManager();
         $instructor = $em->getRepository('ApplicationSonataUserBundle:User')->findOneBy(array('id' => $instructorId));
         $courses = $em->getRepository('QTUTkbBundle:Course')->findCourseByInstructor($instructorId, $time_start, $time_end);
         return $this->render('QTUTkbBundle:MyTimeTable:timetable_instructor.html.twig', array('courses' => $courses, 'instructor' => $instructor));
     } else {
         throw new NotFoundHttpException("Page not found");
     }
 }
开发者ID:princedominh,项目名称:tkb,代码行数:14,代码来源:MyTimeTableController.php

示例5: asyncDBCheck

 /**
  * @Route("/check-connection", name="check-db-connection")
  */
 public function asyncDBCheck(Request $request)
 {
     if ($request->isXMLHttpRequest()) {
         $databaseArgs = array('name' => $request->request->get('name'));
         $connectionStatus = $this->checkConnection($databaseArgs);
         $response = new JsonResponse();
         if ($connectionStatus) {
             $response->setData(array('action' => 'db_check', 'status' => 'success'));
         } else {
             $response->setData(array('action' => 'db_check', 'status' => 'failure'));
         }
         return $response;
     }
     return new Response('This is not ajax!', 400);
 }
开发者ID:rwachtler,项目名称:EasyInstall,代码行数:18,代码来源:DBChecker.php

示例6: RechercheCode

 /**
  * @Route("/code",name="recherchecode")
  * 
  * 
  */
 public function RechercheCode(Request $request)
 {
     if ($request->isXMLHttpRequest()) {
         $code = $request->get('code');
         $codeInfo = $this->container->get('formatecode')->FormateCode($code);
         if ($codeInfo) {
             return new Response(200);
             // Code 200  == ok,, make sure it has the correct content t
         } else {
             return new Response(201);
             //Code 201 == doublons
         }
     } else {
         return new Response(400);
     }
 }
开发者ID:Jrbebel,项目名称:GestionTitre,代码行数:21,代码来源:DefaultController.php

示例7: listAction

 /**                                                                                   
  * @Method({"GET", "POST"})
  */
 public function listAction(Request $request)
 {
     if ($request->isXMLHttpRequest()) {
         $idcategories = $request->request->get("idcategories");
         $code = "";
         $repository = $this->getRepository('SWDocManagerBundle:Category');
         foreach ($idcategories as $idcategory) {
             if ($idcategory > -1) {
                 $code .= $repository->getCode($idcategory);
             }
         }
         $repDoc = $this->getRepository('SWDocManagerBundle:Document');
         $documents = $repDoc->getByCode($code);
         $documentsJson = $this->encodeJson($documents);
         return new JsonResponse(array('code' => $code, 'documents' => json_decode($documentsJson)));
     }
     return $this->redirect($this->generateUrl('sw_doc_manager_homepage'));
 }
开发者ID:adrienManikon,项目名称:docmanager,代码行数:21,代码来源:ViewController.php

示例8: ajaxAction

 public function ajaxAction(Request $request)
 {
     if ($request->isXMLHttpRequest()) {
         $repository = $this->getDoctrine()->getRepository('AppBundle:Prepod');
         $ids = $request->request->get('ids');
         if (sizeof($ids) == 0) {
             $prepods = $repository->findAll();
         } else {
             $prepods = $repository->createQueryBuilder('n')->where('n.id NOT IN (:status)')->setParameter('status', $ids)->getQuery()->getResult();
         }
         $prepod = $prepods[array_rand($prepods)];
         if ($prepod->getId() == 2) {
             return new JsonResponse(array('winner' => 2, 'img' => $prepod->getFoto(), 'name' => $prepod->getName(), 'text' => $prepod->getDescription()));
         }
         if (sizeof($ids) == 2) {
             return new JsonResponse(array('winner' => 1, 'img' => $prepod->getFoto(), 'name' => $prepod->getName(), 'text' => $prepod->getDescription()));
         }
         return new JsonResponse(array('winner' => 0, 'img' => $prepod->getFoto(), 'ids' => $prepod->getId()));
     }
     return new Response('This is not ajax!', 400);
 }
开发者ID:Ar4ics,项目名称:project_1,代码行数:21,代码来源:Roadto86Controller.php

示例9: listAction

 /**
  * @Route(
  *    "/list/{page}/{markViewed}",
  *    requirements = {
  *        "page" = "\d+",
  *        "markViewed" = "0|1"
  *    },
  *    defaults = {
  *        "page" = 1,
  *        "markViewed" = 0
  *    },
  *    name="icap_notification_view"
  * )
  * @Template()
  * @ParamConverter("user", options={"authenticatedUser" = true})
  */
 public function listAction(Request $request, $user, $page, $markViewed)
 {
     $notificationManager = $this->getNotificationManager();
     $systemName = $notificationManager->getPlatformName();
     if ($request->isXMLHttpRequest()) {
         $result = $notificationManager->getDropdownNotifications($user->getId());
         $result['systemName'] = $systemName;
         $unviewedNotifications = $notificationManager->countUnviewedNotifications($user->getId());
         $result['unviewedNotifications'] = $unviewedNotifications;
         return $this->render('IcapNotificationBundle:Templates:notificationDropdownList.html.twig', $result);
     } else {
         $category = $request->get('category');
         if ($markViewed == true) {
             $notificationManager->markAllNotificationsAsViewed($user->getId());
         }
         $result = $notificationManager->getPaginatedNotifications($user->getId(), $page, $category);
         $result['systemName'] = $systemName;
         $result['category'] = $category;
         return $result;
     }
 }
开发者ID:claroline,项目名称:distribution,代码行数:37,代码来源:NotificationController.php

示例10: classFilterAction

 public function classFilterAction(Request $request)
 {
     $time_start = $this->container->getParameter('current_time_start');
     $time_end = $this->container->getParameter('current_time_end');
     //        var_dump($time_start);die;
     if ($request->isXMLHttpRequest()) {
         $className = $request->query->get('class', '');
         $em = $this->getDoctrine()->getManager();
         if ($className != '') {
             $classP = $em->getRepository('QTUTkbBundle:ClassP')->findOneBy(array('stillStudy' => true, 'name' => $className));
             if ($classP) {
                 //get all course of this class
                 $courses = $em->getRepository('QTUTkbBundle:Course')->findCourseByClass($className, $time_start, $time_end);
                 //                    var_dump($courses);die;
                 return $this->render('QTUTkbBundle:Default:timetable_class_filter.html.twig', array('courses' => $courses));
             }
         }
         var_dump($courses);
         return $this->render('QTUTkbBundle:Default:timetable_class_empty.html.twig');
     } else {
         throw new NotFoundHttpException("Page not found");
     }
 }
开发者ID:princedominh,项目名称:tkb,代码行数:23,代码来源:DefaultController.php

示例11: editAction

 /**
  * Displays a form to edit an existing Tasks entity.
  *
  * @Route("/{id}/edit", name="tasks_edit")
  * @Method({"GET", "POST"})
  */
 public function editAction(Request $request, Tasks $task)
 {
     $em = $this->getDoctrine()->getManager();
     if ($request->isXMLHttpRequest()) {
         $task->setCompleted($request->get('completed'));
         if ($task->getCompleted()) {
             $task->setCompletedAt(new \DateTime());
         } else {
             $task->setCompletedAt(null);
         }
         $em->flush();
         return new \Symfony\Component\HttpFoundation\JsonResponse();
     }
     $deleteForm = $this->createDeleteForm($task);
     $editForm = $this->createForm(TasksType::class, $task);
     $editForm->handleRequest($request);
     if ($editForm->isSubmitted() && $editForm->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($task);
         $em->flush();
         return $this->redirect($this->generateUrl('focus') . '#task_' . $task->getId());
     }
     return $this->render('tasks/edit.html.twig', array('task' => $task, 'task_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()));
 }
开发者ID:alexseif,项目名称:myapp,代码行数:30,代码来源:TasksController.php

示例12: inviteFriendAction

 public function inviteFriendAction(Request $request)
 {
     $user = $this->getUser();
     if (!is_object($user) || !$user instanceof UserInterface) {
         throw new AccessDeniedException('This user does not have access to this section.');
     }
     $response = array('success' => 'false');
     if ($request->isXMLHttpRequest() && null !== $request->request->get('email')) {
         $emailTo = $request->request->get('email');
         $emailConstraint = new Assert\Email();
         $emailConstraint->message = 'Invalid email address';
         // use the validator to validate the value
         $errorList = $this->get('validator')->validate($emailTo, $emailConstraint);
         if (0 === count($errorList)) {
             try {
                 $message = \Swift_Message::newInstance()->setSubject('Join CreateSafe')->setFrom(array('createsafedonotreply@gmail.com' => 'CreateSafe'))->setTo($emailTo)->setBody($this->renderView('email/inviteFriends.html.twig', array('confirmationUrl' => '/', 'user' => $this->getUser())), 'text/html');
                 $this->get('mailer')->send($message);
                 $response['success'] = 'true';
             } catch (\Exception $e) {
                 $response['success'] = 'false';
                 //use for debugging purposes
                 //$response['error'] = $e->getMessage();
             }
         } else {
             $response['invalidEmail'] = true;
         }
     }
     $encoders = array(new XmlEncoder(), new JsonEncoder());
     $normalizers = array(new ObjectNormalizer());
     $serializer = new Serializer($normalizers, $encoders);
     return new Response($serializer->serialize($response, 'json'));
 }
开发者ID:DanieleMenara,项目名称:CreateSafe,代码行数:32,代码来源:ProfileController.php

示例13: ajaxUnitsAction

 /**
  * @Route("/wotr/ajax/units/{id}")
  * @ParamConverter("post", class="WotRBundle:Game", options={"repository_method" = "getCurrentGame"})
  * @param Game $game
  * @param Request $request
  * @return JsonResponse|Response
  */
 public function ajaxUnitsAction(Game $game, Request $request)
 {
     if ($request->isXMLHttpRequest()) {
         $units = $game->getUnits();
         $outputArr = array();
         /** @var Unit $u */
         foreach ($units as $u) {
             if ($u->getLocation()) {
                 $outputArr[$u->getId()] = array('unitName' => $u->getName(), 'loc' => $u->getLocation()->getId(), 'sideId' => $u->getSide()->getId());
             }
         }
         $response = new JsonResponse();
         $response->setData(array('data' => $outputArr));
         return $response;
     }
     return new Response('This is not ajax!', 400);
     $unitTable = 'units';
     $request = new Request();
     switch ($request->getProperty('request')) {
         case 'units':
             $sql = "SELECT {$unitTable}.id, loc, unit.name as unitName, unitType.name as type, " . "nation.side_id as sideId, nation.name as nation FROM {$unitTable} " . "LEFT JOIN unit ON unit_id = unit.id " . "LEFT JOIN nation ON nation_id = nation.id " . "LEFT JOIN unitType on unitType_id = unitType.id " . "WHERE loc != 0 " . "ORDER BY {$unitTable}.loc";
             $unitsQ = DBP::query($sql);
             $outputArr = array();
             foreach ($unitsQ->rows as $unit) {
                 $outputArr[$unit->id] = array('unitName' => $unit->unitName, 'loc' => $unit->loc, 'type' => $unit->type, 'nation' => $unit->nation, 'sideId' => $unit->sideId);
             }
             echo json_encode($outputArr);
             break;
         case 'recruitable':
             $sql = "SELECT {$unitTable}.id, IF( ISNULL(unit.name),CONCAT(nation.name, ' ', unitType.name, ' (', COUNT({$unitTable}.id), ' remaining)'),unit.name) AS unitName " . "FROM {$unitTable} " . "LEFT JOIN unit ON {$unitTable}.unit_id = unit.id " . "LEFT JOIN nation ON nation.id = nation_id " . "LEFT JOIN unitType ON unitType.id = unitType_id " . "WHERE loc = 0 AND ( side_id = 2 || casualty != 1 ) AND unit.unitType_id <= 4 " . "GROUP BY CONCAT(nation.name, ' ', unitType.name) " . "UNION ALL " . "SELECT {$unitTable}.id, unit.name AS unitName FROM {$unitTable} " . "LEFT JOIN unit ON {$unitTable}.unit_id = unit.id " . "LEFT JOIN nation ON nation.id = nation_id " . "LEFT JOIN unitType ON unitType.id = unitType_id " . "WHERE loc = 0 AND casualty != 1 AND unit.unitType_id >= 5 " . "ORDER BY id";
             $units = DBP::query($sql, NULL, NULL, 'keyPair');
             echo json_encode($units->rows);
             break;
         case 'recruit':
             $unitID = $request->getProperty('unit');
             $regionID = $request->getProperty('region');
             if ($regionID && $unitID) {
                 $sql = "UPDATE {$unitTable} SET loc = ? WHERE id = ?";
                 $pA = array($regionID, $unitID);
                 DBP::query($sql, $pA);
                 echo "Unit recruited.";
             } else {
                 echo "Please select a unit to recruit.";
             }
             break;
         case 'move':
             $unitIDs = $request->getProperty('selectedUnits');
             $dest = $request->getProperty('dest');
             if (is_array($unitIDs)) {
                 $qMarks = str_repeat('?,', count($unitIDs) - 1) . '?';
                 $sql = "UPDATE {$unitTable} SET loc = ? WHERE id IN ({$qMarks})";
                 array_unshift($unitIDs, $dest);
                 DBP::query($sql, $unitIDs);
                 echo "Units moved";
             } else {
                 echo "Please select units to move";
             }
             break;
         case 'remove':
             $unitIDs = $request->getProperty('selectedUnits');
             $casualty = $request->getProperty('casualty');
             if (is_array($unitIDs)) {
                 $qMarks = str_repeat('?,', count($unitIDs) - 1) . '?';
                 $sql = "UPDATE {$unitTable} SET loc = 0, casualty = ? WHERE id IN ({$qMarks})";
                 array_unshift($unitIDs, $casualty);
                 DBP::query($sql, $unitIDs);
                 echo "Units removed";
             } else {
                 echo "Please select units to remove";
             }
             break;
         case 'reduce':
             $unitIDs = $request->getProperty('selectedUnits');
             $regionID = $request->getProperty('region');
             $return = '';
             foreach ($unitIDs as $unitID) {
                 $sql = "SELECT nation_id FROM {$unitTable} " . "LEFT JOIN unit ON {$unitTable}.unit_id = unit.id " . "WHERE {$unitTable}.id = ?";
                 $result = DBP::query($sql, array($unitID));
                 $nation = $result->nation_id;
                 $sql = "SELECT {$unitTable}.id, casualty FROM {$unitTable} " . "LEFT JOIN unit ON {$unitTable}.unit_id = unit.id " . "WHERE nation_id = ? AND loc = 0 AND unitType_id = 1 " . "ORDER BY casualty DESC";
                 $regulars = DBP::query($sql, array($nation));
                 if ($regulars->getRows()) {
                     $sql = "UPDATE {$unitTable} SET loc = 0, casualty = 1 WHERE id = ?";
                     $pA = array($unitID);
                     DBP::query($sql, $pA);
                     $sql = "UPDATE {$unitTable} SET loc = ?, casualty = 0 WHERE id = ?";
                     $pA = array($regionID, $regulars->id);
                     DBP::query($sql, $pA);
                     $return = 'Elite reduced';
                 } else {
                     $return = 'No regular to reduce elite';
                 }
             }
//.........这里部分代码省略.........
开发者ID:uhtoff,项目名称:WotR,代码行数:101,代码来源:WotRController.php

示例14: UpdateTemplateBlocRowAction

 /**
  * @Route("/admin/page/row/update/template/{id}", name = "page_update_sect_template" )
  * @Template
  */
 public function UpdateTemplateBlocRowAction($id, Request $request)
 {
     $class = $request->request->get('contenu');
     if (!is_numeric($class)) {
         return new Response('error', 400);
     }
     $em = $this->getDoctrine()->getManager();
     if ($request->isXMLHttpRequest()) {
         $section = $em->getRepository('PageBundle:PgBlocrow')->find($id);
         if ($class == 0) {
             if (!$section) {
                 return new Response('error', 400);
             }
             $section->setTemplate(NULL);
             $em->flush();
             return new Response('ok');
         } else {
             $template = $em->getRepository('PageBundle:PgRowTemplate')->find($class);
             if ($template) {
                 if (!$section) {
                     return new Response('error', 400);
                 }
                 $section->setTemplate($template);
                 $em->flush();
                 return new Response('ok');
             } else {
                 return new Response('template(' . $class . ')', 400);
             }
         }
     }
     return new Response('error', 400);
 }
开发者ID:ne0shad0w,项目名称:PageBundle,代码行数:36,代码来源:AjaxController.php

示例15: addFromSiteAction

 /**
  * @Route("/add/site/{id}", name="address_site_add")
  * @Template()
  */
 public function addFromSiteAction(Request $request, $id)
 {
     if ($request->isXMLHttpRequest()) {
     }
     if ($id == 0) {
         throw new Exception('id is needed in the function addAction from AddressController');
     }
     $address = new Address();
     $form = $this->createForm(new AddressType(), $address);
     $form->add('save', 'submit');
     if ($form->handleRequest($request)->isValid() || $request->isXMLHttpRequest()) {
         $em = $this->getDoctrine()->getManager();
         $site = $em->getRepository('SiteBundle:Site')->find($id);
         if ($site == null) {
             throw new Exception('siteId is invalid  in the function addAction from AddressController');
         }
         $site->addAddress($address);
         $address->setSite($site);
         $em->persist($address);
         $em->flush();
         return $this->redirect($this->generateUrl('site_show', array('id' => $site->getId()), 301));
     }
     return $this->render('CoordinateBundle:Address:add.html.twig', array('form' => $form->createView()));
 }
开发者ID:jrsao,项目名称:_idm,代码行数:28,代码来源:AddressController.php


注:本文中的Symfony\Component\HttpFoundation\Request::isXMLHttpRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。