本文整理匯總了PHP中Psr\Http\Message\ResponseInterface::redirect方法的典型用法代碼示例。如果您正苦於以下問題:PHP ResponseInterface::redirect方法的具體用法?PHP ResponseInterface::redirect怎麽用?PHP ResponseInterface::redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Psr\Http\Message\ResponseInterface
的用法示例。
在下文中一共展示了ResponseInterface::redirect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __invoke
/**
* Invoke middleware
*
* @param ServerRequestInterface $request request
* @param ResponseInterface $response response
* @param callable $next callable
*
* @return object ResponseInterface
*/
public function __invoke(Request $request, Response $response, callable $next = null)
{
if ($this->getContainer()->get('user')->identity->guest()) {
$this->getContainer()->get('flash')->info('Your session has been expired.');
return $response->redirect(static::REDIRECT_URI);
}
$err = null;
return $next($request, $response, $err);
}
示例2: __invoke
/**
* Invoke middleware
*
* @param ServerRequestInterface $request request
* @param ResponseInterface $response response
* @param callable $next callable
*
* @return object ResponseInterface
*/
public function __invoke(Request $request, Response $response, callable $next = null)
{
$err = null;
if ($request->isSecure() == false) {
$path = $request->getUri()->getPath();
$host = $request->getUri()->getHost();
return $response->redirect('https://' . $host . $path);
}
return $next($request, $response, $err);
}
示例3: __invoke
/**
* Invoke middleware
*
* @param ServerRequestInterface $request request
* @param ResponseInterface $response response
* @param callable $next callable
*
* @return object ResponseInterface
*/
public function __invoke(Request $request, Response $response, callable $next = null)
{
$err = null;
if (!$this->getContainer()->get('middleware')->isAdded('Translation')) {
throw new RuntimeException('RewriteLocale middleware requires Translation middleware.');
}
if ($request->getMethod() == 'GET') {
$params = $this->getContainer()->get('translator.params');
$segment = $request->getUri()->segment($params['uri']['segment']);
// Get segment http://examples.com/en/welcome (en)
if (!in_array($segment, $params['default']['languages'])) {
$translator = $this->getContainer()->get('translator');
$path = $translator->getLocale() . $request->getUri()->getPath();
return $response->redirect($request->getUri()->withPath($path));
}
}
return $next($request, $response, $err);
}