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


PHP RedirectResponse::setVary方法代码示例

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


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

示例1: redirectRouteAction

 /**
  * Returns a 301/302 redirect response based on content parameters.
  *
  * @param  \Raindrop\RoutingBundle\Routing\Base\ExternalRouteInterface $content
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function redirectRouteAction($content)
 {
     $routeParams = $this->get('request')->query->all();
     // do not lose eventual get parameters
     if ($content instanceof ExternalRouteInterface) {
         /**
          * External redirect
          */
         $http_status = $content->getPermanent() ? 301 : 302;
         $uri = $content->getUri();
         if (count($routeParams)) {
             $uri .= (strpos($uri, '?') === false ? '?' : '&') . http_build_query($routeParams);
         }
     } else {
         /**
          * Inner redirect
          */
         $current_route = $this->get('router')->getRouteCollection()->get($this->getRequest()->get('_route'));
         $http_status = $current_route->getPermanent() ? 301 : 302;
         $uri = $this->get('router')->generate($content->getName(), $routeParams, true);
     }
     $response = new RedirectResponse($uri, $http_status);
     $response->setVary('accept-language');
     return $response;
 }
开发者ID:cwplus,项目名称:RaindropRoutingBundle,代码行数:31,代码来源:GenericController.php

示例2: defaultLanguageAction

 /**
  * action for / to redirect to the best language based on the request language order
  */
 public function defaultLanguageAction(Request $request)
 {
     $defaultPreferredLangs = $this->chooser->getPreferredLanguages($request->getLocale());
     $bestLang = $request->getPreferredLanguage($defaultPreferredLangs);
     // we only care about the first 2 characters, even if the user's preference is de_CH.
     $bestLang = substr($bestLang, 0, 2);
     /* Note: I wanted to send a 300 "Multiple Choices" header along with a
      * Location header, but user agents may behave inconsistently in
      * repsonse to this.
      *
      * For example Chrome was not redirecting unless the headers were
      * carefully tailored for it. (In particular, it doesn't like the
      * lowercase 'location' header that results from calling
      * $response->headers->set('Location', '...')
      */
     $url = $this->router->generate($this->routename, array('_locale' => $bestLang, '/'), true);
     $response = new RedirectResponse($url, 301);
     $response->setVary('accept-language');
     return $response;
 }
开发者ID:ronnylt,项目名称:symfony-cmf,代码行数:23,代码来源:LanguageSelectorController.php

示例3: defaultLanguageAction

 /**
  * action for / to redirect to the best language based on the request language order
  */
 public function defaultLanguageAction(Request $request, $contentDocument)
 {
     if (!$contentDocument instanceof RouteAwareInterface) {
         throw new \Exception('The route passed to the language selection action must emulate content to have the correct route generated.');
     }
     // TODO: use lunetics/LocaleBundle https://github.com/symfony-cmf/cmf-sandbox/issues/54
     $defaultPreferredLangs = $this->chooser->getDefaultLocalesOrder();
     $bestLang = $request->getPreferredLanguage($defaultPreferredLangs);
     // we only care about the first 2 characters, even if the user's preference is de_CH.
     $bestLang = substr($bestLang, 0, 2);
     /*
      * Let the router generate the route for the requested language. The
      * route provides its children, which should be the urls for each locale
      * as content.
      */
     $routeParams = $request->query->all();
     // do not lose eventual get parameters
     $routeParams['_locale'] = $bestLang;
     // and set the locale
     $routeParams['content'] = $contentDocument;
     // and the content for the router
     $url = $this->router->generate('', $routeParams, true);
     /* Note: I wanted to send a 300 "Multiple Choices" header along with a
      * Location header, but user agents may behave inconsistently in
      * response to this.
      *
      * For example Chrome was not redirecting unless the headers were
      * carefully tailored for it. (In particular, it doesn't like the
      * lowercase 'location' header that results from calling
      * $response->headers->set('Location', '...')
      */
     $response = new RedirectResponse($url, 301);
     $response->setVary('accept-language');
     return $response;
 }
开发者ID:richardmiller,项目名称:symfony-cmf,代码行数:38,代码来源:LanguageSelectorController.php


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