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


PHP RedirectResponse::create方法代码示例

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


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

示例1: redirect

    /**
     * Automatically perform any required redirect
     *
     * This method is meant to be a helper for simple scenarios. If you want to customize the
     * redirection page, just call the getRedirectUrl() and getRedirectData() methods directly.
     */
    public function redirect()
    {
        if (!$this instanceof RedirectResponseInterface || !$this->isRedirect()) {
            throw new RuntimeException('This response does not support redirection.');
        }
        if ('GET' === $this->getRedirectMethod()) {
            HttpRedirectResponse::create($this->getRedirectUrl())->send();
            exit;
        } elseif ('POST' === $this->getRedirectMethod()) {
            $hiddenFields = '';
            foreach ($this->getRedirectData() as $key => $value) {
                $hiddenFields .= sprintf('<input type="hidden" name="%1$s" value="%2$s" />', htmlspecialchars($key, ENT_QUOTES, 'UTF-8'), htmlspecialchars($value, ENT_QUOTES, 'UTF-8')) . "\n";
            }
            $output = '<!DOCTYPE html>
<html>
    <head>
        <title>Redirecting...</title>
    </head>
    <body onload="document.forms[0].submit();">
        <form action="%1$s" method="post">
            <p>Redirecting to payment page...</p>
            <p>
                %2$s
                <input type="submit" value="Continue" />
            </p>
        </form>
    </body>
</html>';
            $output = sprintf($output, htmlspecialchars($this->redirectUrl, ENT_QUOTES, 'UTF-8'), $hiddenFields);
            HttpResponse::create($output)->send();
            exit;
        }
        throw new RuntimeException('Invalid redirect method "' . $this->getRedirectMethod() . '".');
    }
开发者ID:ericariyanto,项目名称:omnipay,代码行数:40,代码来源:AbstractResponse.php

示例2: postAction

 public function postAction(Request $request)
 {
     $form = new ConfigurationForm($request);
     try {
         $configForm = $this->validateForm($form);
         $data = $configForm->getData();
         $paylineConfig = new PaylineConfig();
         $paylineConfig->merge($data);
         // Redirect to the success URL,
         if ($this->getRequest()->get('save_mode') == 'stay') {
             // If we have to stay on the same page, redisplay the configuration page/
             $route = '/admin/module/Payline';
         } else {
             // If we have to close the page, go back to the module back-office page.
             $route = '/admin/modules';
         }
         return RedirectResponse::create(URL::getInstance()->absoluteUrl($route));
     } catch (FormValidationException $e) {
         $error = $this->createStandardFormValidationErrorMessage($e);
     } catch (\Exception $e) {
         $error = $e->getMessage();
     }
     $this->setupFormErrorContext('Payline Configuration', $error, $form, $e);
     return $this->render('module-configure', ['module_code' => 'Payline']);
 }
开发者ID:Alban-io,项目名称:Payline,代码行数:25,代码来源:ConfigurationController.php

示例3: onKernelView

 /**
  *
  * Launch the parser defined on the constructor and get the result.
  *
  * The result is transform id needed into a Response object
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $parser = $this->container->get('thelia.parser');
     $templateHelper = $this->container->get('thelia.template_helper');
     $parser->setTemplateDefinition($templateHelper->getActiveFrontTemplate(), true);
     $request = $this->container->get('request_stack')->getCurrentRequest();
     $response = null;
     try {
         $content = $parser->render($request->attributes->get('_view') . ".html");
         if ($content instanceof Response) {
             $response = $content;
         } else {
             $response = new Response($content, $parser->getStatus() ?: 200);
         }
     } catch (ResourceNotFoundException $e) {
         throw new NotFoundHttpException();
     } catch (OrderException $e) {
         switch ($e->getCode()) {
             case OrderException::CART_EMPTY:
                 // Redirect to the cart template
                 $response = RedirectResponse::create($this->container->get('router.chainRequest')->generate($e->cartRoute, $e->arguments, Router::ABSOLUTE_URL));
                 break;
             case OrderException::UNDEFINED_DELIVERY:
                 // Redirect to the delivery choice template
                 $response = RedirectResponse::create($this->container->get('router.chainRequest')->generate($e->orderDeliveryRoute, $e->arguments, Router::ABSOLUTE_URL));
                 break;
         }
         if (null === $response) {
             throw $e;
         }
     }
     $event->setResponse($response);
 }
开发者ID:vigourouxjulien,项目名称:thelia,代码行数:41,代码来源:ViewListener.php

示例4: authenticationException

 public function authenticationException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof AuthenticationException) {
         $event->setResponse(RedirectResponse::create($exception->getLoginTemplate()));
     }
 }
开发者ID:margery,项目名称:thelia,代码行数:7,代码来源:ErrorListener.php

示例5: handle

 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $currentRoute = $request->attributes->get('_route');
     if (!$this->session->has('LDAP_LOGIN_CALLBACK')) {
         if (in_array($currentRoute, $this->allowedRoutes)) {
             $this->session->set('LDAP_LOGIN_CALLBACK', $this->kernel->getParameter('rheck_ldap_firewall.default_url'));
         } else {
             $this->session->set('LDAP_LOGIN_CALLBACK', $currentRoute);
         }
     }
     if (in_array($currentRoute, $this->allowedRoutes)) {
         return;
     }
     if (!$this->session->has('LDAP_LOGIN')) {
         $loginUrl = $this->router->generate($this->kernel->getParameter('rheck_ldap_firewall.login_url'));
         $event->setResponse(RedirectResponse::create($loginUrl));
         return;
     }
     $ldapUserCredentials = $this->session->get('LDAP_LOGIN');
     $token = new LDAPToken();
     $token->setUser('ldap_proxy_user');
     $token->setLDAPUserCredentials($ldapUserCredentials);
     try {
         $authToken = $this->authenticationManager->authenticate($token);
         $this->securityContext->setToken($authToken);
     } catch (AuthenticationException $failed) {
         $this->session->set('LDAP_LOGIN_ERROR', 'Some error was occurred! Can\'t connect to LDAP.');
         $event->setResponse(RedirectResponse::create($this->router->generate('_rheck_ldap_login')));
     } catch (\Exception $e) {
         $this->session->set('LDAP_LOGIN_ERROR', 'Invalid credentials.');
         $event->setResponse(RedirectResponse::create($this->router->generate('_rheck_ldap_login')));
     }
 }
开发者ID:rheck,项目名称:ldapfirewall-bundle,代码行数:34,代码来源:LDAPListener.php

示例6: loginAction

 public function loginAction()
 {
     $customerController = new BaseCustomerController();
     $customerController->setContainer($this->container);
     $response = $customerController->loginAction();
     if (!$this->getSecurityContext()->hasCustomerUser()) {
         $request = $this->getRequest();
         $customerLoginForm = new CustomerLogin($request);
         try {
             $form = $this->validateForm($customerLoginForm, "post");
             $request = CustomerTempQuery::create();
             $customerTemp = $request->where('`customer_temp`.email = ?', $form->get('email')->getData(), \PDO::PARAM_STR)->where('`customer_temp`.password = PASSWORD(?)', $form->get('password')->getData(), \PDO::PARAM_STR)->where('`customer_temp`.processed = 0')->findOne();
             if (null !== $customerTemp) {
                 $customer = CustomerQuery::create()->findOneByEmail($form->get('email')->getData());
                 $customer->setPassword($form->get('password')->getData())->save();
                 $customerTemp->setProcessed(true)->save();
                 $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, new CustomerLoginEvent($customer));
                 $successUrl = $customerLoginForm->getSuccessUrl();
                 $response = RedirectResponse::create($successUrl);
             }
         } catch (\Exception $e) {
         }
     }
     return $response;
 }
开发者ID:JumBay,项目名称:ImportT1,代码行数:25,代码来源:CustomerController.php

示例7: showFront

 /** {@inheritdoc} */
 public function showFront(Template $template = null)
 {
     if (is_array($this->languages) && count($this->languages)) {
         // allowed languages
         $allowedLanguages = array();
         foreach ($this->languages as $lang) {
             $allowedLanguages[$lang['code']] = $lang;
         }
         // find preferred language
         reset($this->languages);
         $language = current($this->languages);
         foreach ($this->getLanguage() as $lang => $quality) {
             if (array_key_exists($lang, $allowedLanguages)) {
                 $language = $allowedLanguages[$lang];
                 break;
             }
         }
         $page = \PageQuery::create()->findPk($language['page_id']);
         if ($page) {
             return RedirectResponse::create(url($page->getUrl(), $_GET));
         } else {
             $this->app->logger->notice('Redirect page not found');
         }
     } else {
         $this->app->logger->notice('No languages found');
     }
     return '';
 }
开发者ID:bombayworks,项目名称:currycms,代码行数:29,代码来源:Language.php

示例8: checkRedirectException

 public function checkRedirectException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof \Thelia\Core\HttpKernel\Exception\RedirectException) {
         $response = RedirectResponse::create($exception->getUrl(), $exception->getStatusCode());
         $event->setResponse($response);
     }
 }
开发者ID:alex63530,项目名称:thelia,代码行数:8,代码来源:RedirectException.php

示例9: trackAction

 /**
  * When a simple web user click a referral link, this code is executed.
  *
  * A hash is defined in the route ( at least should be defined ), so we
  * can retrieve referral line given this hash.
  *
  * If hash exists, current hash is saved in the cookie, so if user
  * registers or makes a purchase, this value will be used for
  * referral program engine.
  *
  * If cookie is already set, hash value is overwritten.
  *
  * @return Response Response object
  */
 public function trackAction()
 {
     $hash = $this->requestStack->getCurrentRequest()->query->get('hash');
     $cookie = new Cookie(ElcodiReferralProgramCookie::REFERRAL_PROGRAM_COOKIE_NAME, $hash);
     $responseUrl = $this->urlGenerator->generate($this->controllerRedirect);
     $response = RedirectResponse::create($responseUrl);
     $response->headers->setCookie($cookie);
     return $response;
 }
开发者ID:hd-deman,项目名称:elcodi,代码行数:23,代码来源:ReferralProgramController.php

示例10: redirect

 public function redirect($url, $way = 'html', $status = '301', $header = array())
 {
     $redirectResponse = RedirectResponse::create($url, $status, $header);
     if ('html' === $way) {
         $content = $redirectResponse->getContent();
         $this->renderTrait('redirect.tpl', ['content' => $content]);
     } else {
         return $redirectResponse;
     }
 }
开发者ID:renyunhuang,项目名称:nodephp,代码行数:10,代码来源:AppController.php

示例11: redirect

 /**
  * Redirect to URL or close dialog.
  *
  * @param string $url
  * @param bool $dialogRedirect If true, this will redirect dialogs as well, otherwise just close the dialog.
  */
 public static function redirect($url, $dialogRedirect = true)
 {
     $url = (string) $url;
     $redirectJs = '<script type="text/javascript">window.location.href = ' . json_encode($url) . ';</script>';
     if (isAjax()) {
         // we're in a dialog, use javascript to redirect
         self::returnPartial($dialogRedirect ? $redirectJs : '');
     } else {
         throw new ResponseException(RedirectResponse::create($url));
     }
 }
开发者ID:bombayworks,项目名称:currycms,代码行数:17,代码来源:AbstractLegacyBackend.php

示例12: checkRedirectException

 public function checkRedirectException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof ExceptionRedirectException) {
         $response = RedirectResponse::create($exception->getUrl(), $exception->getStatusCode());
         $event->setResponse($response);
     } elseif ($exception instanceof AuthenticationException) {
         // Redirect to the login template
         $response = RedirectResponse::create($this->urlManager->viewUrl($exception->getLoginTemplate()));
         $event->setResponse($response);
     }
 }
开发者ID:vigourouxjulien,项目名称:thelia,代码行数:12,代码来源:RedirectException.php

示例13: saveAction

 public function saveAction()
 {
     if (null !== ($response = $this->checkAuth(AdminResources::MODULE, ['Twitter'], AccessManager::UPDATE))) {
         return $response;
     }
     $form = new ConfigurationForm($this->getRequest());
     $configurationForm = $this->validateForm($form);
     $consumer_key = $configurationForm->get('consumer_key')->getData();
     $consumer_secret = $configurationForm->get('consumer_secret')->getData();
     $screen_name = $configurationForm->get('screen_name')->getData();
     $count = $configurationForm->get('count')->getData();
     $cache_lifetime = $configurationForm->get('cache_lifetime')->getData();
     // $debug_mode     = $configurationForm->get('debug_mode')->getData();
     $errorMessage = null;
     $response = null;
     // Save config values
     ConfigQuery::write('twitter_consumer_key', $consumer_key, 1, 1);
     ConfigQuery::write('twitter_consumer_secret', $consumer_secret, 1, 1);
     ConfigQuery::write('twitter_screen_name', $screen_name, 1, 1);
     ConfigQuery::write('twitter_count', $count, 1, 1);
     ConfigQuery::write('twitter_cache_lifetime', $cache_lifetime * 60, 1, 1);
     // Minutes
     ConfigQuery::write('twitter_last_updated', 0, 1, 1);
     if ($screen_name && $consumer_key && $consumer_secret) {
         if (!extension_loaded('openssl')) {
             $sslError = $this->getTranslator()->trans("This module requires the PHP extension open_ssl to work.", [], Twitter::DOMAIN_NAME);
         } else {
             $config = array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret, 'output_format' => 'array');
             try {
                 $connection = new TwitterOAuth($config);
                 $bearer_token = $connection->getBearerToken();
             } catch (\Exception $e) {
                 $errorMessage = $e->getMessage();
             }
             try {
                 $params = array('screen_name' => $screen_name, 'count' => 1, 'exclude_replies' => true);
                 $response = $connection->get('statuses/user_timeline', $params);
                 if ($response['error']) {
                     throw new TwitterException($response['error']);
                 }
             } catch (\Exception $e) {
                 $erroMessage = $this->getTranslator()->trans("Unrecognized screen name", [], Twitter::DOMAIN_NAME);
             }
         }
     }
     $response = RedirectResponse::create(URL::getInstance()->absoluteUrl('/admin/module/Twitter'));
     if (null !== $errorMessage) {
         $this->setupFormErrorContext($this->getTranslator()->trans("Twitter configuration failed.", [], Twitter::DOMAIN_NAME), $errorMessage, $form);
         $response = $this->render("module-configure", ['module_code' => 'Twitter']);
     }
     return $response;
 }
开发者ID:nicolasleon,项目名称:Twitter,代码行数:52,代码来源:ConfigurationController.php

示例14: getRedirectResponse

 public function getRedirectResponse()
 {
     if (!$this instanceof RedirectResponseInterface || !$this->isRedirect()) {
         throw new RuntimeException('This response does not support redirection.');
     }
     if ('GET' === $this->getRedirectMethod()) {
         return HttpRedirectResponse::create($this->getRedirectUrl());
     } elseif ('POST' === $this->getRedirectMethod()) {
         $xml = $this->toXml($this->getRedirectData());
         return HttpResponse::create(parent::postXmlCurl($xml, $this->getRedirectUrl(), false));
     }
     throw new RuntimeException('Invalid redirect method "' . $this->getRedirectMethod() . '".');
 }
开发者ID:udoless,项目名称:omnipay-weixin,代码行数:13,代码来源:QrPurchaseResponse.php

示例15: update

 public function update($author, $name)
 {
     $package = Package::where('author', '=', $author)->where('name', '=', $name)->get()->first();
     $minRefresh = Carbon::now()->subMinutes(30)->timestamp;
     if (is_null($package)) {
         return RedirectResponse::create('/?no_such_package');
     } elseif (strtotime($package->updated_at) > $minRefresh) {
         return RedirectResponse::create('/package/' . $author . '/' . $name . '?too_quick');
     } else {
         $this->_refreshPackage($package);
         return RedirectResponse::create('/package/' . $author . '/' . $name);
     }
 }
开发者ID:Jleagle,项目名称:php-packages.com,代码行数:13,代码来源:PackageController.php


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