本文整理汇总了PHP中Psr\Http\Message\ResponseInterface::withRedirect方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::withRedirect方法的具体用法?PHP ResponseInterface::withRedirect怎么用?PHP ResponseInterface::withRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ResponseInterface
的用法示例。
在下文中一共展示了ResponseInterface::withRedirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callback
/**
*
* @param Request $request
* @param Response $response
* @param array $args
*/
public function callback(Request $request, Response $response, $args)
{
// cleanup the session
$this->session->clear();
if ($this->facebook->getAccessToken()) {
return $response->withRedirect($this->router->pathFor('home'));
}
return $response->withRedirect($this->router->pathFor('login'));
}
示例2: postSignin
public function postSignin(Request $request, Response $response, $args)
{
$req = $request->getParsedBody();
$hashed_password = hash('sha1', $req['password']);
$query = "SELECT * FROM users WHERE email =:email AND password=:password";
$stmt = $this->db->prepare($query);
$stmt->execute(['email' => $req['email'], 'password' => $hashed_password]);
$isExist = $stmt->rowCount();
$userData = $stmt->fetch(\PDO::FETCH_OBJ);
if ($isExist == 1) {
$this->session->set('auth', $userData);
$this->flash->addMessage('success', 'Login Successful');
return $response->withRedirect($this->router->pathFor('admin'));
} else {
$this->flash->addMessage('error', 'Data Not Found');
return $response->withRedirect($this->router->pathFor('admin/signup'));
}
}
示例3: login
public function login(Request $req, Response $res, $args)
{
$this->logger->info('Login page request');
if (isset($_POST) && isset($_POST['username']) && isset($_POST['password'])) {
$user = $this->userManager->getByUsername($_POST['username']);
$password = hash('sha512', $_POST['password']);
if ($user && $password == $user->getPassword()) {
$this->logger->notice('Login succeed [' . $user->getUsername() . ']');
$_SESSION['login'] = $user->getUsername();
return $res->withRedirect($this->router->pathFor('login'));
} else {
$this->logger->error('Login failed');
$this->flash->addMessage('error', 'Authentification failed.');
return $res->withRedirect($this->router->pathFor('login'));
}
}
$this->view->render($res, 'Default/home.html.twig');
return $res;
}
示例4: __invoke
/**
* Example middleware invokable class
*
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
* @param \Psr\Http\Message\ResponseInterface $response PSR7 response
* @param callable $next Next middleware
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function __invoke($request, $response, $next)
{
// check if user is authenticated, otherwise return 401/ redirect/ etc
if (!$this->auth->isAuthenticated()) {
// return $response->withStatus(401);
return $response->withRedirect('/session/login', 401);
}
// pass onto the next callable
$response = $next($request, $response);
return $response;
}
示例5: get
/**
*
*/
public function get(ServerRequestInterface $request, ResponseInterface $response)
{
if (!$this->auth->check()) {
return $this->auth->redirectToLogin();
} elseif (!$this->auth->hasAccess(['admin'])) {
return $response->withRedirect($this->url['root']);
}
parent::preparePage();
$this->importView('Main:sb2/dashboard as content');
return parent::withBody($response);
}
示例6: put
/**
*
*/
public function put(ServerRequestInterface $request, ResponseInterface $response)
{
if (!$this->auth->check()) {
return $this->auth->redirectToLogin();
} elseif (!$this->auth->hasAccess(['admin'])) {
return $response->withRedirect($this->url['root']);
}
$data = $request->getParsedBody();
// Process the input data and generate proper response, specific to each application.
$responseData = json_encode(['method' => 'PUT', 'data' => $data]);
return parent::withBody($response, $responseData);
}
示例7: __invoke
/**
* Remove trailing slash from any request.
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param callable $next
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function __invoke(Request $request, Response $response, callable $next)
{
$uri = $request->getUri();
$path = $uri->getPath();
if ($path != '/' && substr($path, -1) == '/') {
// permanently redirect paths with a trailing slash
// to their non-trailing counterpart
$uri = $uri->withPath(substr($path, 0, -1));
return $response->withRedirect((string) $uri, 301);
}
return $next($request, $response);
}
示例8: get
/**
*
*/
public function get(ServerRequestInterface $request, ResponseInterface $response)
{
if (!$this->auth->check()) {
return $this->auth->redirectToLogin();
} elseif (!$this->auth->hasAccess(['admin'])) {
return $response->withRedirect($this->url['root']);
}
parent::preparePage();
$args = func_get_arg(2);
$this->importView("Sb2:{$args['view']} as content");
return parent::withBody($response);
}
示例9: __invoke
/**
* @param Container $container A DI (Pimple) container.
* @param RequestInterface $request A PSR-7 compatible Request instance.
* @param ResponseInterface $response A PSR-7 compatible Response instance.
* @return ResponseInterface
*/
public function __invoke(Container $container, RequestInterface $request, ResponseInterface $response)
{
$config = $this->config();
// Handle explicit redirects
if (!empty($config['redirect'])) {
$uri = $this->parseRedirect($config['redirect'], $request);
if ($uri) {
return $response->withRedirect($uri, $config['redirect_mode']);
}
}
$templateContent = $this->templateContent($container, $request);
$response->write($templateContent);
return $response;
}
示例10: listAll
/**
*
*/
public function listAll(ServerRequestInterface $request, ResponseInterface $response)
{
if (!$this->auth->check()) {
return $this->auth->redirectToLogin();
} elseif (!$this->auth->hasAccess($this->requiredPermissions)) {
return $response->withRedirect($this->app['urlRoot']);
}
parent::preparePage();
$rolesModel = new Models\Roles();
$rst = $rolesModel->selectAll();
$this->importView("Auth:roles/list-all as content");
$url_Roles = Auth::getUrlRoot() . "/auth/roles";
$this->template->setData(['rst' => $rst, 'txt_pageTitle' => $this->locale->say('roles page title'), 'txt_th_Name' => $this->locale->say('roles table title name'), 'txt_th_Slug' => $this->locale->say('roles table title slug'), 'txt_th_Permissions' => $this->locale->say('roles table title permissions'), 'txt_btn_NewRole' => $this->locale->say('roles table btn new role'), 'url_Roles' => $url_Roles, 'url_NewRole' => "{$url_Roles}/0"]);
return parent::withBody($response);
}
示例11: __invoke
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$path = $request->getUri()->getPath();
if ($path == '/install') {
if (file_exists(DATABASE . DS . 'config.yml')) {
return $response->withRedirect('/');
}
return $next($request, $response);
} elseif ($path == '/api/v1/install') {
return $next($request, $response);
} elseif ($path != '/install') {
if (!file_exists(DATABASE . DS . 'config.yml')) {
return $response->withRedirect('install');
}
return $next($request, $response);
}
return $next($request, $response);
}
示例12: logoutAndRediret
private function logoutAndRediret(Response $res, $message)
{
$this->authService->clearIdentity();
$this->flash->addMessage('danger', $message);
return $res->withRedirect($this->unitNotFoundRedirectUrl);
}
示例13: resultsdelete
/**
*
* @param Request $request
* @param Response $response
* @param unknown $args
*/
public function resultsdelete(Request $request, Response $response, $args)
{
$id = $args['id'];
$record = R::load(USER, $id);
if ($record) {
R::trash($record);
}
return $response->withRedirect($this->router->pathFor('results'));
}
示例14: deallocate_action
/**
* Deallocate a user's current resource
*
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
* @param \Psr\Http\Message\ResponseInterface $response PSR7 response
* @param array $args Args passed in from URL
* @return \Psr\Http\Message\ResponseInterface Final PSR7 response
*/
public function deallocate_action($request, $response, $args)
{
$resource_id = $request->getParsedBody()['resource_id'];
$this->resource_action->destroy_resource($resource_id);
return $response->withRedirect($this->router->pathFor('list-resources'));
}
示例15: delete
public function delete(Request $request, Response $response, $args)
{
$kpi_entity = $this->em->getRepository('App\\Entity\\Kpi')->findOneById($args['id']);
$this->em->remove($kpi_entity);
$this->em->flush();
return $response->withRedirect($this->router->pathFor('kpi'));
}