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


PHP JsonResponse::setCallback方法代码示例

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


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

示例1: 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

示例2: JsonData

 /**
  * @Route("/admin/testimonials/jsondata", name="admin_testimonials_jsondata")
  */
 public function JsonData(Request $request)
 {
     $sortColumn = $request->get('sidx');
     $sortDirection = $request->get('sord');
     $pageSize = $request->get('rows');
     $page = $request->get('page');
     $callback = $request->get('callback');
     $repo = $this->getDoctrineRepo('AppBundle:Testimonial');
     $dataRows = $repo->getGridOverview($sortColumn, $sortDirection, $pageSize, $page);
     $rowsCount = $repo->countAll();
     $pagesCount = ceil($rowsCount / $pageSize);
     $rows = array();
     // rows as json result
     foreach ($dataRows as $dataRow) {
         // build single row
         $row = array();
         $row['id'] = $dataRow->getId();
         $cell = array();
         $i = 0;
         $cell[$i++] = '';
         $cell[$i++] = $dataRow->getId();
         $cell[$i++] = $dataRow->getName();
         $cell[$i++] = $dataRow->getAge();
         $cell[$i++] = $dataRow->getPlace();
         $cell[$i++] = $dataRow->getPosition();
         $row['cell'] = $cell;
         array_push($rows, $row);
     }
     $result = array('records' => $rowsCount, 'page' => $page, 'total' => $pagesCount, 'rows' => $rows);
     $resp = new JsonResponse($result, JsonResponse::HTTP_OK);
     $resp->setCallback($callback);
     return $resp;
 }
开发者ID:artur-dante,项目名称:heyrentme,代码行数:36,代码来源:TestimonialController.php

示例3: subtreesJsonp

 /**
  * Returns the rendered subtree of each top-level toolbar link.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function subtreesJsonp()
 {
     _toolbar_initialize_page_cache();
     $subtrees = toolbar_get_rendered_subtrees();
     $response = new JsonResponse($subtrees);
     $response->setCallback('Drupal.toolbar.setSubtrees.resolve');
     return $response;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:13,代码来源:ToolbarController.php

示例4: json

 protected function json($req, $data, $status = 200)
 {
     $resp = new JsonResponse($data, $status);
     if ($req->query->has('callback')) {
         $resp->setCallback($req->query->get('callback'));
     }
     return $resp;
 }
开发者ID:anpone,项目名称:sitecake,代码行数:8,代码来源:Service.php

示例5: postPageviewAction

 /**
  * @Route("/track/pageview", name="track_pageview")
  *
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function postPageviewAction(Request $request)
 {
     $trackedCustomerStorage = new SessionStorage($request->getSession());
     $command = new AddNewPageviewEventCommand($trackedCustomerStorage);
     $command->url = $request->query->get('url');
     $command->ip = $request->getClientIp();
     $command->customerId = $request->query->get('customer', null);
     $command->referrer = $request->query->get('referrer', null);
     $this->get('command_bus')->handle($command);
     $response = new JsonResponse(null, 201);
     $response->setCallback($request->query->get('callback'));
     return $response;
 }
开发者ID:ThreeDotsLabs,项目名称:crm,代码行数:20,代码来源:TrackController.php

示例6: loadPopupStyleAction

 /**
  * Generates a JavaScript file with popup CSS file loader.
  *
  * @param Request $request
  * @return JsonResponse
  */
 public function loadPopupStyleAction(Request $request)
 {
     $style_name = $request->attributes->get('style');
     if (!$style_name) {
         $style_name = ChatStyle::getDefaultStyle();
     }
     $style = new ChatStyle($style_name);
     $configs = $style->getConfigurations();
     $response = new JsonResponse();
     if ($configs['chat']['iframe']['css']) {
         $generator = $this->getAssetManager()->getUrlGenerator();
         $css = $generator->generate($style->getFilesPath() . '/' . $configs['chat']['iframe']['css'], UrlGeneratorInterface::ABSOLUTE_URL);
         $response->setData($css);
         $response->setCallback('Mibew.Utils.loadStyleSheet');
     }
     return $response;
 }
开发者ID:abhijitroy07,项目名称:mibew,代码行数:23,代码来源:StyleController.php

示例7: getPostsAction

 /**
  * @param Request $request
  * @param int     $max
  * @param string  $provider
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function getPostsAction(Request $request, $max = 5, $provider = null)
 {
     $posts = $this->getPostRepository()->retrieveMostRecentPublicPosts($max, $provider);
     /** @var ThumbnailExtension $thumbnailService */
     $thumbnailService = $this->get('genj_thumbnail.twig.thumbnail_extension');
     $postList = array();
     /** @var Post $post */
     foreach ($posts as $post) {
         $postData = array('provider' => $post->getProvider(), 'postId' => $post->getPostId(), 'author' => array('username' => $post->getAuthorUsername(), 'name' => $post->getAuthorName(), 'avatar' => (string) $thumbnailService->getThumbnailPath($post, 'authorFileUpload', 'teaser')), 'body' => $post->getHeadline(), 'image' => (string) $thumbnailService->getThumbnailPath($post, 'fileUpload', 'teaser'), 'link' => $post->getLink(), 'publishAt' => $post->getPublishAt()->format('Y-m-d H:i:s'));
         $postList[] = $postData;
     }
     $response = new JsonResponse(array('posts' => $postList), 200, array());
     $callback = $request->get('callback', false);
     if ($callback) {
         $response->setCallback($callback);
     }
     return $response;
 }
开发者ID:Apolli,项目名称:GenjSocialFeedBundle,代码行数:26,代码来源:SocialFeedController.php

示例8: serve

 /**
  * {@inheritdoc}
  */
 public function serve($params = null)
 {
     $return = $params ? true : false;
     $key = $this->request->request->get('key');
     $callback = $this->request->query->get('callback');
     $configString = $this->request->request->get('data');
     if ($callback && $this->request->isXmlHttpRequest()) {
         $configString = $this->request->query->get('data');
     }
     $publicMethods = array($this->request->query->get('method'), $this->request->request->get('method'));
     $response = new JsonResponse();
     $response->setCallback($callback);
     $response->headers->set('Access-Control-Allow-Headers', 'origin, content-type, accept');
     $response->headers->set('Access-Control-Allow-Origin', '*');
     $response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
     if ($this->request->isXmlHttpRequest()) {
         $key = $this->request->query->get('key');
     }
     $data = array('error' => true, 'message' => 'Invalid config');
     $serviceHandler = get_class($this->serviceHandler);
     $server = new $serviceHandler($this->authentication, $this->connectionStrings, $this->logDir);
     if (in_array('getAvailableDrivers', $publicMethods)) {
         $data = $server->getAvailableDrivers();
     } elseif ($configString) {
         $configString = json_decode($configString, true);
         if (is_array($configString) && isset($configString['config'])) {
             $config = isset($configString['config']) ? $configString['config'] : array();
             $sql = isset($configString['sql']) ? $configString['sql'] : '';
             $limit = isset($configString['limit']) ? intval($configString['limit']) : 500;
             $offset = isset($configString['offset']) ? intval($configString['offset']) : 0;
             $single = isset($configString['single']) ? (bool) $configString['single'] : false;
             $data = $server->getResult($config, $sql, $limit, $offset, $single, $key, 'array');
             if (in_array('getServerVersion', $publicMethods)) {
                 $data = $server->getServerVersion();
             }
         }
     }
     $response->setData($data);
     if (!$return) {
         $response->send();
     } else {
         return $response;
     }
 }
开发者ID:realboard,项目名称:dbinstance,代码行数:47,代码来源:RestService.php

示例9: getCategoryForApiAction

 /**
  * Get List From API Access
  *
  * @Route("/api/{categoryCode}/{callback}", name="category_get_category", requirements={"categoryCode" = "^[a-z0-9]*$"}, defaults={"callback" = null})
  * @Method("GET")
  */
 public function getCategoryForApiAction(Request $request, $categoryCode, $callback)
 {
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository('AtwTestBundle:Category')->findOneBy(['categoryCode' => $categoryCode]);
     $output = null;
     if (!is_null($entity)) {
         $output["name"] = htmlspecialchars($entity->getName());
         $output["categoryCode"] = htmlspecialchars($entity->getCategoryCode());
     }
     $response = new JsonResponse();
     $response->setData($output);
     $response->setStatusCode(Response::HTTP_OK);
     // if error...
     //$response->setStatusCode(500);
     if (isset($callback)) {
         $response->setCallback($callback);
     }
     return $response;
 }
开发者ID:pinekta,项目名称:mysymfonysample,代码行数:25,代码来源:CategoryController.php

示例10: JsonData

 /**
  * @Route("/admin/users/jsondata", name="admin_users_jsondata")
  */
 public function JsonData(Request $request)
 {
     $sortColumn = $request->get('sidx');
     $sortDirection = $request->get('sord');
     $pageSize = $request->get('rows');
     $page = $request->get('page');
     $callback = $request->get('callback');
     $email = $request->get('u_email');
     $name = $request->get('u_name');
     $surname = $request->get('u_surname');
     $enabled = $request->get('u_enabled');
     $createdAt = $request->get('u_createdAt');
     $modifiedAt = $request->get('u_modifiedAt');
     $repo = $this->getDoctrineRepo('AppBundle:User');
     $dataRows = $repo->getGridOverview($sortColumn, $sortDirection, $pageSize, $page, $email, $name, $surname, $enabled, $createdAt, $createdAt, $modifiedAt);
     $rowsCount = $repo->countAll();
     $pagesCount = ceil($rowsCount / $pageSize);
     $rows = array();
     // rows as json result
     foreach ($dataRows as $dataRow) {
         // build single row
         $row = array();
         $row['id'] = $dataRow->getId();
         $cell = array();
         $i = 0;
         $cell[$i++] = "";
         $cell[$i++] = $dataRow->getId();
         $cell[$i++] = $dataRow->getUsername();
         $cell[$i++] = $dataRow->getName();
         $cell[$i++] = $dataRow->getSurname();
         $cell[$i++] = $dataRow->isEnabled();
         $cell[$i++] = $dataRow->getCreatedAt()->format('Y-m-d H:i');
         $cell[$i++] = $dataRow->getModifiedAt()->format('Y-m-d H:i');
         $row['cell'] = $cell;
         array_push($rows, $row);
     }
     $result = array('records' => $rowsCount, 'page' => $page, 'total' => $pagesCount, 'rows' => $rows);
     $resp = new JsonResponse($result, JsonResponse::HTTP_OK);
     $resp->setCallback($callback);
     return $resp;
 }
开发者ID:artur-dante,项目名称:heyrentme,代码行数:44,代码来源:UserController.php

示例11: json

 /**
  * Convert some data into a JSON response.
  *
  * @param mixed   $data    The response data
  * @param integer $status  The response status code
  * @param array   $headers An array of response headers
  * @return JsonResponse
  * @see JsonResponse
  */
 public function json($data = [], $status = 200, array $headers = [])
 {
     $request = $this['request_stack']->getMasterRequest();
     if ($request->query->has('fields') && !($status >= 400 && $status < 500)) {
         $fields = $this['rest.fields'];
         $fields->addParameter('id');
         $data = $this['rest.filter']->filter($data);
     }
     $flags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
     if ($request->query->get('pretty', true)) {
         $flags |= JSON_PRETTY_PRINT;
     }
     $response = new JsonResponse();
     $response->headers->replace($headers);
     $response->setStatusCode($status);
     $response->setEncodingOptions($flags);
     $response->setData($data);
     if ($request->query->has('callback')) {
         $response->setCallback($request->query->get('callback'));
     }
     return $response;
 }
开发者ID:mehulsbhatt,项目名称:RestServiceProvider,代码行数:31,代码来源:RestTrait.php

示例12: findTopicsAction

 /**
  * @Route("/topics_search/")
  */
 public function findTopicsAction(Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         // retrieve query and page_limit
         $q = $request->query->get('term');
         $p = $request->query->get('page_limit');
         $locale = $request->getLocale();
         $topics = $this->get('em')->getRepository('Newscoop\\NewscoopBundle\\Entity\\Topic')->searchTopics($q, array(), $p, $locale)->getArrayResult();
         array_walk($topics, function (&$topic, $key) {
             $topic['term'] = $topic['title'];
             $topic = array_intersect_key($topic, array_flip(array('id', 'term')));
         });
         $arr = array('results' => array('items' => $topics));
         $response = new JsonResponse($arr);
         $response->setCallback($request->query->get('callback'));
         return $response;
     }
     throw new BadRequestHttpException('Only XHR supported');
 }
开发者ID:riverans,项目名称:plugin-IngestPluginBundle,代码行数:22,代码来源:FeedController.php

示例13: JsonData

 /**
  * @Route("/admin/category/jsondata", name="admin_category_jsondata")
  */
 public function JsonData(Request $request)
 {
     $sortColumn = $request->get('sidx');
     $sortDirection = $request->get('sord');
     $pageSize = $request->get('rows');
     $page = $request->get('page');
     $callback = $request->get('callback');
     $repo = $this->getDoctrineRepo('AppBundle:Category');
     $dataRows = $repo->getGridOverview($sortColumn, $sortDirection, $pageSize, $page);
     $rowsCount = $repo->countAll();
     $pagesCount = ceil($rowsCount / $pageSize);
     $rows = array();
     // rows as json result
     foreach ($dataRows as $dataRow) {
         // build single row
         $row = array();
         $row['id'] = $dataRow->getId();
         $cell = array();
         $cell[0] = null;
         $cell[1] = $dataRow->getId();
         $cell[2] = $dataRow->getName();
         $cell[3] = $dataRow->getSlug();
         $cell[4] = $dataRow->getPosition();
         $row['cell'] = $cell;
         array_push($rows, $row);
     }
     $result = array('records' => $rowsCount, 'page' => $page, 'total' => $pagesCount, 'rows' => $rows);
     $resp = new JsonResponse($result, JsonResponse::HTTP_OK);
     $resp->setCallback($callback);
     return $resp;
     /*
             
             $rows = $this->GetData($sortColumn, $sortDirection, $pageSize, $page);
             $rowsCount = $this->getDoctrineRepo('AppBundle:Category')->countAll();
             $pagesCount =   ceil($rowsCount/$pageSize);
             
             $rowsStr = "";
             $rowsTemplate = '{ "id": %s, "cell": [null, "%s", "%s", "%s", "%s" ] }';
             $i = 0;
             foreach($rows as $row){
                 if ($i > 0) {
                     $rowsStr .= ", ";
                 }
                 $rowsStr .= sprintf($rowsTemplate, $row->getId(), $row->getId(), $row->getName(), $row->getSlug(), $row->getPosition() );
                 $i .=1;
             }
             
             $json = sprintf('{ "records":%s,"page":%s ,"total":%s ,"rows": [ %s ] }', $rowsCount, $page, $pagesCount, $rowsStr );
             
             $response = new Response();
             $response->setContent('/**/
     /*'.$method.'('. $json .')');
        $response->headers->set('Content-Type', 'text/javascript');
        return $response;
       */
 }
开发者ID:artur-dante,项目名称:heyrentme,代码行数:59,代码来源:CategoryController.php

示例14: errorResponse

 private function errorResponse($msg, Request $request)
 {
     $response = new JsonResponse(['message' => $msg, 'success' => false]);
     return $response->setCallback($request->get('callback'));
 }
开发者ID:campaignchain,项目名称:core,代码行数:5,代码来源:TrackingController.php

示例15: createJsonmResponse

 /**
  * JSONM
  * https://github.com/lifesinger/lifesinger.github.com/issues/118
  */
 protected function createJsonmResponse($data)
 {
     $response = new JsonResponse($data);
     $response->setCallback('define');
     return $response;
 }
开发者ID:liugang19890719,项目名称:www.zesow.com,代码行数:10,代码来源:BaseController.php


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