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


PHP JsonResponse::create方法代码示例

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


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

示例1: contactSendAction

 public function contactSendAction(Request $request)
 {
     $contact = $request->get('email');
     $message = \Swift_Message::newInstance()->setSubject('CONSULTA WEB')->setFrom($contact['userEmail'], $contact['name'])->setTo('odiseo.team@gmail.com')->setBody($contact['body'], 'text/html');
     $this->get('mailer')->send($message);
     return JsonResponse::create(array());
 }
开发者ID:odiseoteam,项目名称:odiseo-team-website,代码行数:7,代码来源:HomeController.php

示例2: getTagAction

 public function getTagAction(Request $request)
 {
     $q = $request->get('q');
     $em = $this->getDoctrine()->getManager();
     $result = $em->getRepository('AcmeBlogBundle:Tag')->findTagsByName($q);
     return JsonResponse::create($result);
 }
开发者ID:tarnawski,项目名称:Blog,代码行数:7,代码来源:TagController.php

示例3: obtenerDatosPanillaNormal

 public function obtenerDatosPanillaNormal($central_id, $planilla_id)
 {
     $planilla = Planilla::find($planilla_id);
     $planilla['tipo'] = 'normal';
     $planilla->load('viaje.conductor', 'central.ciudad.departamento');
     return JsonResponse::create($planilla);
 }
开发者ID:andybolano,项目名称:viaja_seguro,代码行数:7,代码来源:PlanillaController.php

示例4: testCreate

 public function testCreate()
 {
     $response = JsonResponse::create(array('foo' => 'bar'), 204);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\JsonResponse', $response);
     $this->assertEquals('{"foo":"bar"}', $response->getContent());
     $this->assertEquals(204, $response->getStatusCode());
 }
开发者ID:nicodmf,项目名称:symfony,代码行数:7,代码来源:JsonResponseTest.php

示例5: wrapResponse

 public function wrapResponse($response)
 {
     if (!$response instanceof Response) {
         $response = is_scalar($response) ? Response::create($response) : JsonResponse::create($response);
     }
     return $response;
 }
开发者ID:buuum,项目名称:app,代码行数:7,代码来源:DispatchProvider.php

示例6: __invoke

 public function __invoke(\Exception $e, $code)
 {
     $error = array("code" => $e->getCode(), "message" => $e->getMessage());
     if ($this->app["debug"]) {
         $error["trace"] = $e->getTraceAsString();
     }
     return JsonResponse::create($error);
 }
开发者ID:jdesrosiers,项目名称:resourceful,代码行数:8,代码来源:JsonErrorHandler.php

示例7: start

 /**
  * @param Request $request
  *   The request that resulted in an AuthenticationException
  *
  * @param AuthenticationException $authException
  *   The exception that started the authentication process
  *
  * @return Response
  */
 public function start(Request $request, AuthenticationException $authException = null)
 {
     $responseData = ['error' => 'Unauthorized'];
     if (!is_null($authException)) {
         $responseData['details'] = $authException->getMessage();
     }
     return JsonResponse::create($responseData, 401);
 }
开发者ID:cultuurnet,项目名称:symfony-security-jwt,代码行数:17,代码来源:JwtAuthenticationEntryPoint.php

示例8: testHandlingNonIlluminateResponseErrorResponses

 public function testHandlingNonIlluminateResponseErrorResponses()
 {
     $response = JsonResponse::create(['format' => 'json'], 500);
     $formatted = $this->formatter->formatResult($response);
     $this->assertJsonResponse($formatted, 500);
     $response = Response::create('<html>', 500);
     $formatted = $this->formatter->formatResult($response);
     $this->assertNormalResponse($formatted, 500);
 }
开发者ID:etorofiev,项目名称:laravel-batch-request,代码行数:9,代码来源:OptimusResultFormatterTest.php

示例9: stationStateAction

 /**
  * @Route("/stationstate")
  * @Method("GET")
  */
 public function stationStateAction()
 {
     $repository = $this->getDoctrine()->getRepository('StationMapping:StationState');
     $data = $repository->findLastSnapshot();
     return JsonResponse::create(array_map(function (StationState $stationState) {
         $station = $stationState->getStation();
         return array('name' => $station->getName(), 'id' => $station->getId(), 'statusCode' => $stationState->getStatusCode(), 'availableBikes' => $stationState->getAvailableBikes(), 'freeSlots' => $stationState->getFreeSlots(), 'latitude' => $station->getLatitude(), 'longitude' => $station->getLongitude());
     }, $data));
 }
开发者ID:alexcarol,项目名称:bicing-stats,代码行数:13,代码来源:ApiController.php

示例10: getUserByIdAction

 /**
  * @param $id
  * @return Response
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\OptimisticLockException
  * @throws \Doctrine\ORM\TransactionRequiredException
  * @ApiDoc(
  *                                                    resource=true,
  *                                                    description="get user by id"
  *                                                    )
  * @Get("/public/user/get/{id}", defaults={"id" = null})
  */
 public function getUserByIdAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $user = $em->find('OjsUserBundle:User', $id);
     if ($user) {
         return JsonResponse::create(['id' => $id, 'text' => $user->getUsername() . " <" . $user->getEmail() . '>']);
     }
     throw new NotFoundHttpException();
 }
开发者ID:necatikartal,项目名称:ojs,代码行数:21,代码来源:PublicUserRestController.php

示例11: connect

 public function connect(Application $app)
 {
     // Creates a new controller based on the default route
     $controllers = $app['controllers_factory'];
     $controllers->post('/json', function (Request $request, Application $app) {
         if ($request->request->has('email')) {
             $email = new EmailAddress($request->request->get('email'));
         } else {
             $email = null;
         }
         $selection = $request->request->get('selection');
         $include = $request->request->get('include');
         $command = new ExportEventsAsJsonLD(new EventExportQuery($request->request->get('query')), $email, $selection, $include);
         /** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
         $commandBus = $app['event_command_bus'];
         $commandId = $commandBus->dispatch($command);
         return JsonResponse::create(['commandId' => $commandId]);
     });
     $controllers->post('/csv', function (Request $request, Application $app) {
         if ($request->request->has('email')) {
             $email = new EmailAddress($request->request->get('email'));
         } else {
             $email = null;
         }
         $selection = $request->request->get('selection');
         $include = $request->request->get('include');
         $command = new ExportEventsAsCSV(new EventExportQuery($request->request->get('query')), $email, $selection, $include);
         /** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
         $commandBus = $app['event_command_bus'];
         $commandId = $commandBus->dispatch($command);
         return JsonResponse::create(['commandId' => $commandId]);
     });
     $controllers->post('/ooxml', function (Request $request, Application $app) {
         if ($request->request->has('email')) {
             $email = new EmailAddress($request->request->get('email'));
         } else {
             $email = null;
         }
         $selection = $request->request->get('selection');
         $include = $request->request->get('include');
         $command = new ExportEventsAsOOXML(new EventExportQuery($request->request->get('query')), $email, $selection, $include);
         /** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
         $commandBus = $app['event_command_bus'];
         $commandId = $commandBus->dispatch($command);
         return JsonResponse::create(['commandId' => $commandId]);
     });
     $controllers->post('/pdf', function (Request $request, Application $app) {
         $deserializer = new ExportEventsAsPDFJSONDeserializer();
         $command = $deserializer->deserialize(new String($request->getContent()));
         /** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
         $commandBus = $app['event_command_bus'];
         $commandId = $commandBus->dispatch($command);
         return JsonResponse::create(['commandId' => $commandId]);
     });
     return $controllers;
 }
开发者ID:Axxon,项目名称:udb3-silex,代码行数:56,代码来源:ExportEventsControllerProvider.php

示例12: handle

 public function handle(Request $request)
 {
     // Fetch client_id from authenticated token.
     $clientId = $this->checkClientId();
     // Check refresh_token, then fetch username and scope.
     list($username, $scope) = $this->checkRefreshToken($request, $clientId);
     // Generate access_token, store to backend and set token response.
     $parameters = $this->tokenTypeHandlerFactory->getTokenTypeHandler()->createAccessToken($clientId, $username, $scope);
     return JsonResponse::create($parameters, 200, ['Cache-Control' => 'no-store', 'Pragma' => 'no-cache']);
 }
开发者ID:miguelbemartin,项目名称:oauth2-php,代码行数:10,代码来源:RefreshTokenGrantTypeHandler.php

示例13: setStatusAjaxAction

 public function setStatusAjaxAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $objLoan = $em->getRepository('DataBundle:Loan')->find($request->get('id'));
     $status = (int) $request->get('status');
     /* @var $objLoan \DataBundle\Entity\Loan */
     $objLoan->setStatus($status);
     $em->flush();
     return \Symfony\Component\HttpFoundation\JsonResponse::create(array('status' => 'success', 'new_status_label' => $objLoan->getStatusLabel(), 'message' => 'Pożyczka o ID równym ' . $objLoan->getId() . ' zmieniła status na ' . $objLoan->getStatusLabel()));
 }
开发者ID:jgadek,项目名称:epozyczki,代码行数:10,代码来源:LoanController.php

示例14: searchunread

 /**
  * Action for route /markpostunread/searchunread
  *
  * Returns the text for the 'Unread posts' search link in JSON
  */
 public function searchunread()
 {
     // Don't allow usage if default behaviour is selected
     if ($this->core->cfg('unread_posts_link') == 0) {
         throw new \phpbb\exception\http_exception(403, 'NOT_AUTHORISED');
     }
     $response = array('search_unread' => $this->core->get_search_unread_text());
     $headers = array('Cache-Control' => 'no-cache', 'Pragma' => 'no-cache', 'Expires' => '0');
     return JsonResponse::create($response, 200, $headers);
 }
开发者ID:phpbb-es,项目名称:phpbb-ext-markpostunread,代码行数:15,代码来源:controller.php

示例15: getUser

 /**
  * @return JsonResponse
  */
 public function getUser()
 {
     $user = null;
     $minimalUserInfo = $this->userSessionService->getMinimalUserInfo();
     if (is_null($minimalUserInfo)) {
         return new Response('No active user.', Response::HTTP_NOT_FOUND);
     }
     $user = $this->userService->getUser($minimalUserInfo->getId());
     return JsonResponse::create()->setData($user)->setPrivate();
 }
开发者ID:cultuurnet,项目名称:silex-uitid-provider,代码行数:13,代码来源:UserController.php


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