本文整理汇总了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()));
}
示例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;
}
示例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');
}