當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。