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


PHP RedirectResponse::setStatusCode方法代码示例

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


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

示例1: handle

 /**
  * Handles an access denied failure redirecting to home page
  *
  * @param Request               $request
  * @param AccessDeniedException $accessDeniedException
  *
  * @return Response may return null
  */
 public function handle(Request $request, AccessDeniedException $accessDeniedException)
 {
     $this->logger->error('User tried to access: ' . $request->getUri());
     if ($request->isXmlHttpRequest()) {
         return new JsonResponse(['message' => $accessDeniedException->getMessage(), 'trace' => $accessDeniedException->getTraceAsString(), 'exception' => get_class($accessDeniedException)], Response::HTTP_SERVICE_UNAVAILABLE);
     } else {
         $url = $request->getBasePath() !== "" ? $request->getBasePath() : "/";
         $response = new RedirectResponse($url);
         $response->setStatusCode(Response::HTTP_FORBIDDEN);
         $response->prepare($request);
         return $response->send();
     }
 }
开发者ID:QuangDang212,项目名称:roadiz,代码行数:21,代码来源:AccessDeniedHandler.php

示例2: realpath

/* Ensure requested file is actually in the content folder.
 * You'd think I'd do this sooner, but we don't know the actual
 * filename before this point.
 */
$filename = realpath($filename);
if (strpos($filename, realpath(__DIR__ . '/../content')) !== 0) {
    // Attempt to read file outside of content folder
    $filename = __DIR__ . '/../content/404.html';
}
/* Render the file:
 * Dispatch a FileCopyEvent to call transformers on a file, then build a response
 */
$event = new FileCopyEvent($filename, $filename);
$extension = $event->getExtension();
$event = $container->get('event_dispatcher')->dispatch(FilesystemEvents::COPY, $event);
$response = new Response($event->getContent(), 200);
$headers = $event->data->get('headers')->getOrElse(array());
// Special cases
if (isset($headers['location'])) {
    $response = new RedirectResponse($headers['location']);
    unset($headers['location']);
}
if (isset($headers['status'])) {
    $response->setStatusCode($headers['status']);
    unset($headers['status']);
}
// Everything else
foreach ($headers as $key => $value) {
    $response->headers->set($key, $value);
}
$response->send();
开发者ID:shauncjones,项目名称:site-builder,代码行数:31,代码来源:dev.php


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