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


PHP JsonResponse::setPrivate方法代码示例

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


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

示例1: searchAction

 /**
  * The search action first render an empty page, if the query is set, then the template generates
  * some ajax request to retrieve results for each admin. The Ajax query returns a JSON response.
  *
  * @param Request $request
  *
  * @return JsonResponse|Response
  *
  * @throws \RuntimeException
  */
 public function searchAction(Request $request)
 {
     if ($request->get('admin') && $request->isXmlHttpRequest()) {
         try {
             $admin = $this->getAdminPool()->getAdminByAdminCode($request->get('admin'));
         } catch (ServiceNotFoundException $e) {
             throw new \RuntimeException('Unable to find the Admin instance', $e->getCode(), $e);
         }
         if (!$admin instanceof AdminInterface) {
             throw new \RuntimeException('The requested service is not an Admin instance');
         }
         $handler = $this->getSearchHandler();
         $results = array();
         if ($pager = $handler->search($admin, $request->get('q'), $request->get('page'), $request->get('offset'))) {
             foreach ($pager->getResults() as $result) {
                 $results[] = array('label' => $admin->toString($result), 'link' => $admin->generateObjectUrl('edit', $result), 'id' => $admin->id($result));
             }
         }
         $response = new JsonResponse(array('results' => $results, 'page' => $pager ? (int) $pager->getPage() : false, 'total' => $pager ? (int) $pager->getNbResults() : false));
         $response->setPrivate();
         return $response;
     }
     return $this->render($this->container->get('sonata.admin.pool')->getTemplate('search'), array('base_template' => $this->getBaseTemplate(), 'breadcrumbs_builder' => $this->get('sonata.admin.breadcrumbs_builder'), 'admin_pool' => $this->container->get('sonata.admin.pool'), 'query' => $request->get('q'), 'groups' => $this->getAdminPool()->getDashboardGroups()));
 }
开发者ID:ejkun,项目名称:SonataAdminBundle,代码行数:34,代码来源:CoreController.php

示例2: subtreesJsonp

 /**
  * Returns the rendered subtree of each top-level toolbar link.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function subtreesJsonp()
 {
     $subtrees = toolbar_get_rendered_subtrees();
     $response = new JsonResponse($subtrees);
     $response->setCallback('Drupal.toolbar.setSubtrees.resolve');
     // The Expires HTTP header is the heart of the client-side HTTP caching. The
     // additional server-side page cache only takes effect when the client
     // accesses the callback URL again (e.g., after clearing the browser cache
     // or when force-reloading a Drupal page).
     $max_age = 365 * 24 * 60 * 60;
     $response->setPrivate();
     $response->setMaxAge($max_age);
     $expires = new \DateTime();
     $expires->setTimestamp(REQUEST_TIME + $max_age);
     $response->setExpires($expires);
     return $response;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:22,代码来源:ToolbarController.php

示例3: rateAction

 public function rateAction(Request $request)
 {
     // Retreive and normalise query parameters
     // Epic security here, this would obviously be the current logged in user's ID
     $user_id = $request->query->get('user_id');
     $id = $request->query->get('comment_id');
     $vote = $request->query->get('vote');
     switch ($vote) {
         case 'up':
             $value = 1;
             break;
         case 'down':
             $value = -1;
             break;
         default:
             $value = false;
     }
     $makeResponse = function ($data, $statusCode = 200) use($user_id, $id, $vote) {
         $output = $this->presentResponse($data, 'comment_rating_add', array('vote' => $vote, 'user_id' => $user_id, 'comment_id' => $id));
         $resp = new JsonResponse($output, $statusCode);
         $resp->setPrivate();
         $resp->setMaxAge(0);
         return $resp;
     };
     // Make sure the vote is valid
     if ($value === false) {
         return $makeResponse('Param "vote" invalid. Expected "up" or "down"', Response::HTTP_BAD_REQUEST);
     }
     // Make sure it's a valid comment we're voting on
     $comment = $this->getCommentById($id);
     if (!$comment) {
         return $makeResponse('Comment not found for id ' . $id, Response::HTTP_NOT_FOUND);
     }
     // Make sure they haven't already voted on the comment
     $ratingRepo = $this->getDoctrine()->getRepository('AppBundle:CommentRating');
     $rating = $ratingRepo->findBy(array('user_id' => $user_id));
     if (!!$rating) {
         return $makeResponse('User has already submitted rating', Response::HTTP_BAD_REQUEST);
     }
     try {
         // If we made it here, everything looks good
         $result = $ratingRepo->addNewVote(array('comment_id' => $id, 'value' => $value, 'user_id' => $user_id));
     } catch (Exception $e) {
         return $makeResponse('Failed to save vote', Response::HTTP_INTERNAL_SERVER_ERROR);
     }
     return $makeResponse('Vote Added');
 }
开发者ID:joshrp,项目名称:comment-rating-test,代码行数:47,代码来源:CommentsRatingController.php


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