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


PHP ResponseInterface::setRedirect方法代码示例

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


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

示例1: aroundDispatch

 /**
  * Dispatch request
  *
  * @param \Magento\Framework\App\Action\Action $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->_appState->isInstalled()) {
         $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
         $this->_response->setRedirect($this->_url->getUrl('install'));
         return $this->_response;
     }
     return $proceed($request);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:17,代码来源:Install.php

示例2: execute

 /**
  * Log out user and redirect to new admin custom url
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.ExitExpression)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) {
         return;
     }
     $this->_authSession->destroy();
     $adminUrl = $this->_backendData->getHomePageUrl();
     $this->_response->setRedirect($adminUrl)->sendResponse();
     exit(0);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:AfterCustomUrlChangedObserver.php

示例3: execute

 /**
  * Log out user and redirect him to new admin custom url
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) {
         return;
     }
     $this->_authSession->destroy();
     $route = $this->_backendData->getAreaFrontName();
     $this->_response->setRedirect($this->_storeManager->getStore()->getBaseUrl() . $route)->sendResponse();
     exit(0);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:17,代码来源:AfterCustomUrlChangedObserver.php

示例4: match

 /**
  * Validate and Match Blog Pages and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $_identifier = trim($request->getPathInfo(), '/');
     if (strpos($_identifier, 'blog') !== 0) {
         return;
     }
     $identifier = str_replace(array('blog/', 'blog'), '', $_identifier);
     $condition = new \Magento\Framework\DataObject(['identifier' => $identifier, 'continue' => true]);
     $this->_eventManager->dispatch('magefan_blog_controller_router_match_before', ['router' => $this, 'condition' => $condition]);
     if ($condition->getRedirectUrl()) {
         $this->_response->setRedirect($condition->getRedirectUrl());
         $request->setDispatched(true);
         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]);
     }
     if (!$condition->getContinue()) {
         return null;
     }
     $identifier = $condition->getIdentifier();
     $success = false;
     $info = explode('/', $identifier);
     if (!$identifier) {
         $request->setModuleName('blog')->setControllerName('index')->setActionName('index');
         $success = true;
     } elseif (count($info) > 1) {
         $store = $this->_storeManager->getStore()->getId();
         switch ($info[0]) {
             case 'post':
                 $post = $this->_postFactory->create();
                 $postId = $post->checkIdentifier($info[1], $this->_storeManager->getStore()->getId());
                 if (!$postId) {
                     return null;
                 }
                 $request->setModuleName('blog')->setControllerName('post')->setActionName('view')->setParam('id', $postId);
                 $success = true;
                 break;
             case 'category':
                 $category = $this->_categoryFactory->create();
                 $categoryId = $category->checkIdentifier($info[1], $this->_storeManager->getStore()->getId());
                 if (!$categoryId) {
                     return null;
                 }
                 $request->setModuleName('blog')->setControllerName('category')->setActionName('view')->setParam('id', $categoryId);
                 $success = true;
                 break;
             case 'archive':
                 $request->setModuleName('blog')->setControllerName('archive')->setActionName('view')->setParam('date', $info[1]);
                 $success = true;
                 break;
             case 'search':
                 $request->setModuleName('blog')->setControllerName('search')->setActionName('index')->setParam('q', $info[1]);
                 $success = true;
                 break;
         }
     }
     if (!$success) {
         return null;
     }
     $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $_identifier);
     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
 }
开发者ID:prachicis,项目名称:test_res,代码行数:66,代码来源:Router.php

示例5: match

 /**
  * Validate and Match Cms Page and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  *
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->_appState->isInstalled()) {
         $this->_response->setRedirect($this->_url->getUrl('install'))->sendResponse();
         exit;
     }
     $identifier = trim($request->getPathInfo(), '/');
     $condition = new \Magento\Framework\Object(array('identifier' => $identifier, 'continue' => true));
     $this->_eventManager->dispatch('cms_controller_router_match_before', array('router' => $this, 'condition' => $condition));
     $identifier = $condition->getIdentifier();
     if ($condition->getRedirectUrl()) {
         $this->_response->setRedirect($condition->getRedirectUrl());
         $request->setDispatched(true);
         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request));
     }
     if (!$condition->getContinue()) {
         return null;
     }
     /** @var \Magento\Cms\Model\Page $page */
     $page = $this->_pageFactory->create();
     $pageId = $page->checkIdentifier($identifier, $this->_storeManager->getStore()->getId());
     if (!$pageId) {
         return null;
     }
     $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', $pageId);
     $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', array('request' => $request));
 }
开发者ID:aiesh,项目名称:magento2,代码行数:36,代码来源:Router.php

示例6: match

 /**
  * Validate and Match Cms Page and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $identifier = trim($request->getPathInfo(), '/');
     $urlRewrite = $this->urlMatcher->match($identifier, $this->storeManager->getStore()->getId());
     if ($urlRewrite === null) {
         return null;
     }
     $redirectType = $urlRewrite->getRedirectType();
     if ($redirectType) {
         $redirectCode = $redirectType == \Magento\UrlRedirect\Model\OptionProvider::PERMANENT ? 301 : 302;
         $this->response->setRedirect($urlRewrite->getTargetPath(), $redirectCode);
         $request->setDispatched(true);
         return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request));
     }
     $request->setPathInfo('/' . $urlRewrite->getTargetPath());
     return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Forward', array('request' => $request));
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:23,代码来源:Router.php

示例7: match

 /**
  * Validate and Match News Author and modify request
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  * //TODO: maybe remove this and use the url rewrite table.
  */
 public function match(RequestInterface $request)
 {
     if (!$this->dispatched) {
         $urlKey = trim($request->getPathInfo(), '/');
         $origUrlKey = $urlKey;
         /** @var Object $condition */
         $condition = new Object(['url_key' => $urlKey, 'continue' => true]);
         $this->eventManager->dispatch('sample_news_controller_router_match_before', ['router' => $this, 'condition' => $condition]);
         $urlKey = $condition->getUrlKey();
         if ($condition->getRedirectUrl()) {
             $this->response->setRedirect($condition->getRedirectUrl());
             $request->setDispatched(true);
             return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]);
         }
         if (!$condition->getContinue()) {
             return null;
         }
         $entities = ['author' => ['prefix' => $this->scopeConfig->getValue('sample_news/author/url_prefix', ScopeInterface::SCOPE_STORES), 'suffix' => $this->scopeConfig->getValue('sample_news/author/url_suffix', ScopeInterface::SCOPE_STORES), 'list_key' => $this->scopeConfig->getValue('sample_news/author/list_url', ScopeInterface::SCOPE_STORES), 'list_action' => 'index', 'factory' => $this->authorFactory, 'controller' => 'author', 'action' => 'view', 'param' => 'id']];
         foreach ($entities as $entity => $settings) {
             if ($settings['list_key']) {
                 if ($urlKey == $settings['list_key']) {
                     $request->setModuleName('sample_news')->setControllerName($settings['controller'])->setActionName($settings['list_action']);
                     $request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $urlKey);
                     $this->dispatched = true;
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
                 }
             }
             if ($settings['prefix']) {
                 $parts = explode('/', $urlKey);
                 if ($parts[0] != $settings['prefix'] || count($parts) != 2) {
                     continue;
                 }
                 $urlKey = $parts[1];
             }
             if ($settings['suffix']) {
                 $suffix = substr($urlKey, -strlen($settings['suffix']) - 1);
                 if ($suffix != '.' . $settings['suffix']) {
                     continue;
                 }
                 $urlKey = substr($urlKey, 0, -strlen($settings['suffix']) - 1);
             }
             /** @var \Sample\News\Model\Author $instance */
             $instance = $settings['factory']->create();
             $id = $instance->checkUrlKey($urlKey, $this->storeManager->getStore()->getId());
             if (!$id) {
                 return null;
             }
             $request->setModuleName('sample_news')->setControllerName('author')->setActionName('view')->setParam('id', $id);
             $request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $origUrlKey);
             $request->setDispatched(true);
             $this->dispatched = true;
             return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
         }
     }
     return null;
 }
开发者ID:nhc,项目名称:Magento2SampleModule,代码行数:62,代码来源:Router.php

示例8: _redirectIfNeededAfterLogin

 /**
  * Checks, whether Magento requires redirection after successful admin login, and redirects user, if needed
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 protected function _redirectIfNeededAfterLogin(\Magento\Framework\App\RequestInterface $request)
 {
     $requestUri = null;
     // Checks, whether secret key is required for admin access or request uri is explicitly set
     if ($this->_url->useSecretKey()) {
         $requestUri = $this->_url->getUrl('*/*/*', ['_current' => true]);
     } elseif ($request) {
         $requestUri = $request->getRequestUri();
     }
     if (!$requestUri) {
         return false;
     }
     $this->_response->setRedirect($requestUri);
     $this->_actionFlag->set('', \Magento\Framework\App\ActionInterface::FLAG_NO_DISPATCH, true);
     return true;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:22,代码来源:Authentication.php

示例9: load

 /**
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return bool
  */
 public function load(RequestInterface $request, ResponseInterface $response)
 {
     $orderId = (int) $request->getParam('order_id');
     if (!$orderId) {
         $request->initForward();
         $request->setActionName('noroute');
         $request->setDispatched(false);
         return false;
     }
     $order = $this->orderFactory->create()->load($orderId);
     if ($this->orderAuthorization->canView($order)) {
         $this->registry->register('current_order', $order);
         return true;
     }
     $response->setRedirect($this->url->getUrl('*/*/history'));
     return false;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:22,代码来源:OrderLoader.php

示例10: redirect

 /**
  * Set redirect into response
  *
  * @param \Magento\Framework\App\ResponseInterface $response
  * @param string $path
  * @param array $arguments
  * @return void
  */
 public function redirect(\Magento\Framework\App\ResponseInterface $response, $path, $arguments = [])
 {
     $arguments = $this->updatePathParams($arguments);
     $response->setRedirect($this->_urlBuilder->getUrl($path, $arguments));
 }
开发者ID:nja78,项目名称:magento2,代码行数:13,代码来源:Redirect.php

示例11: redirect

 /**
  * @param \Magento\Framework\App\RequestInterface $request
  * @param string $url
  * @param int $code
  * @return \Magento\Framework\App\ActionInterface
  */
 protected function redirect($request, $url, $code)
 {
     $this->response->setRedirect($url, $code);
     $request->setDispatched(true);
     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:Router.php

示例12: loadValidOrder

 /**
  * Try to load valid order by $_POST or $_COOKIE
  *
  * @param App\RequestInterface $request
  * @param App\ResponseInterface $response
  * @return bool
  */
 public function loadValidOrder(App\RequestInterface $request, App\ResponseInterface $response)
 {
     if ($this->_customerSession->isLoggedIn()) {
         $response->setRedirect($this->_urlBuilder->getUrl('sales/order/history'));
         return false;
     }
     $post = $request->getPost();
     $errors = false;
     /** @var $order \Magento\Sales\Model\Order */
     $order = $this->_orderFactory->create();
     if (empty($post) && !$this->_coreCookie->get(self::COOKIE_NAME)) {
         $response->setRedirect($this->_urlBuilder->getUrl('sales/guest/form'));
         return false;
     } elseif (!empty($post) && isset($post['oar_order_id']) && isset($post['oar_type'])) {
         $type = $post['oar_type'];
         $incrementId = $post['oar_order_id'];
         $lastName = $post['oar_billing_lastname'];
         $email = $post['oar_email'];
         $zip = $post['oar_zip'];
         if (empty($incrementId) || empty($lastName) || empty($type) || !in_array($type, array('email', 'zip')) || $type == 'email' && empty($email) || $type == 'zip' && empty($zip)) {
             $errors = true;
         }
         if (!$errors) {
             $order->loadByIncrementId($incrementId);
         }
         $errors = true;
         if ($order->getId()) {
             $billingAddress = $order->getBillingAddress();
             if (strtolower($lastName) == strtolower($billingAddress->getLastname()) && ($type == 'email' && strtolower($email) == strtolower($billingAddress->getEmail()) || $type == 'zip' && strtolower($zip) == strtolower($billingAddress->getPostcode()))) {
                 $errors = false;
             }
         }
         if (!$errors) {
             $toCookie = base64_encode($order->getProtectCode() . ':' . $incrementId);
             $this->_coreCookie->set(self::COOKIE_NAME, $toCookie, self::COOKIE_LIFETIME, self::COOKIE_PATH);
         }
     } elseif ($this->_coreCookie->get(self::COOKIE_NAME)) {
         $fromCookie = $this->_coreCookie->get(self::COOKIE_NAME);
         $cookieData = explode(':', base64_decode($fromCookie));
         $protectCode = isset($cookieData[0]) ? $cookieData[0] : null;
         $incrementId = isset($cookieData[1]) ? $cookieData[1] : null;
         $errors = true;
         if (!empty($protectCode) && !empty($incrementId)) {
             $order->loadByIncrementId($incrementId);
             if ($order->getProtectCode() == $protectCode) {
                 $this->_coreCookie->renew(self::COOKIE_NAME, self::COOKIE_LIFETIME, self::COOKIE_PATH);
                 $errors = false;
             }
         }
     }
     if (!$errors && $order->getId()) {
         $this->_coreRegistry->register('current_order', $order);
         return true;
     }
     $this->messageManager->addError(__('You entered incorrect data. Please try again.'));
     $response->setRedirect($this->_urlBuilder->getUrl('sales/guest/form'));
     return false;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:65,代码来源:Guest.php

示例13: _redirect

 /**
  * Set redirect into response
  *
  * @param   string $path
  * @param   array $arguments
  * @return \Magento\Framework\App\ResponseInterface
  * @TODO move method
  */
 protected function _redirect($path, $arguments = [])
 {
     $this->_session->setIsUrlNotice($this->_flag->get('', \Magento\Backend\App\AbstractAction::FLAG_IS_URLS_CHECKED));
     $this->_response->setRedirect($this->_helper->getUrl($path, $arguments));
     return $this->_response;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:FileFactory.php

示例14: redirect

 /**
  * Set redirect into response
  *
  * @param \Magento\Framework\App\ResponseInterface $response
  * @param string $path
  * @param array $arguments
  * @return void
  */
 public function redirect(\Magento\Framework\App\ResponseInterface $response, $path, $arguments = array())
 {
     if ($this->_session->getCookieShouldBeReceived() && $this->_urlBuilder->getUseSession() && $this->_canUseSessionIdInParam) {
         $arguments += array('_query' => array($this->_sidResolver->getSessionIdQueryParam($this->_session) => $this->_session->getSessionId()));
     }
     $response->setRedirect($this->_urlBuilder->getUrl($path, $arguments));
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:15,代码来源:Redirect.php

示例15: render

 /**
  * {@inheritdoc}
  */
 protected function render(App\ResponseInterface $response)
 {
     $response->setRedirect($this->url);
     return $this;
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:8,代码来源:Redirect.php


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