本文整理汇总了PHP中Slim\Http\Response::withRedirect方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::withRedirect方法的具体用法?PHP Response::withRedirect怎么用?PHP Response::withRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Response
的用法示例。
在下文中一共展示了Response::withRedirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: goBack
public function goBack()
{
if ($this->request->hasHeader('HTTP_REFERER')) {
$referer = $this->request->getHeader('HTTP_REFERER')[0];
return $this->response->withRedirect($referer, 301);
}
return $this->goHome();
}
示例2: test
public function test(Request $request, Response $response, array $args)
{
$uid = $args['uid'];
$myaccount = R::load('accounts', $uid);
$accountId = $myaccount->accountid;
$account = R::findOne('accounts', ' accountid = ?', [$accountId]);
if (!empty($account)) {
$apiKey = $account['apikey'];
$type = $account['servertype'];
$oandaInfo = new Broker_Oanda($type, $apiKey, $accountId);
} else {
$this->flash->addMessage('flash', "Oanda AccountId not found");
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('homepage'));
}
$side = 'buy';
$pair = 'EUR_USD';
$price = '1.1400';
$expiry = time() + 60;
$stopLoss = '1.1300';
$takeProfit = NULL;
$risk = 1;
// $side='buy';
// $pair='GBP_CHF';
// $price='2.1443';
// $expiry = $oandaInfo->getExpiry(time()+60);
// $stopLoss='2.1452';
// $takeProfit=NULL;
// $risk=1;
//$oandaInfo->placeLimitOrder($side,$pair,$price,$expiry,$stopLoss,$takeProfit,$risk);
$oandaInfo->processTransactions();
}
示例3: __invoke
public function __invoke(Request $req, Response $res)
{
$result = $this->authService->authenticate();
if (!$result->isValid()) {
$this->flash->addMessage('danger', reset($result->getMessages()));
return $res->withRedirect($this->loginUrl);
}
return $res->withRedirect($this->successUrl);
}
示例4: edit
public function edit(Request $request, Response $response, array $args)
{
$uid = $args['uid'];
if (empty($uid)) {
$this->flash->addMessage('flash', 'No record specified');
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('accounts'));
}
$id = $this->authenticator->getIdentity();
$user = R::load('users', $id['id']);
if ($uid != 'new') {
$account = R::load('accounts', $uid);
if ($account->id == 0) {
$this->flash->addMessage('flash', 'No record found');
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('accounts'));
}
// restrict access to own profile or Admin role
if ($account->users->id != $id['id']) {
if (strtolower($id['role']) != 'admin') {
$this->flash->addMessage('flash', 'Access Denied');
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('accounts'));
}
}
} else {
$account = R::dispense('accounts');
}
if ($request->isPost()) {
$data = $request->getParams();
$account->import($data, 'apikey,accountid,servertype');
$account->users = $user;
$account->lasttid = 0;
$oandaInfo = FALSE;
// verify and get account balance
try {
$oandaInfo = new Broker_Oanda($account['servertype'], $account['apikey'], $account['accountid'], 0);
} catch (\Exception $e) {
$viewData['flash'] = 'Account Details Invalid';
}
if ($oandaInfo != FALSE) {
$aid = R::store($account);
$oandaInfo->updateAccount();
$this->flash->addMessage('flash', "account updated");
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('editaccount', ['uid' => $aid]));
}
}
$viewData['account'] = $account;
$this->view->render($response, 'account.twig', $viewData);
return $response;
}
示例5: __invoke
/**
* Execute the middleware.
*
* @param ExtendedRequest $request
* @param Response $response
* @param callable $next
*
* @return Response
*/
public function __invoke(ExtendedRequest $request, Response $response, callable $next)
{
$router = $this->router;
$route = $request->getCurrentRoute();
$locales = $this->locale;
$locale = $locales->getDefault();
$lang = $route->getArgument($router->getLanguageIdentifier());
$lang = ltrim($lang, '/');
$redirect = false;
if ($lang) {
try {
// Find language in list of available locales and set it as active
$locale = $locales->findByLanguage($lang);
$locales->setActive($locale);
if ($router->isOmitDefaultLanguage() && $locale == $locales->getDefault()) {
// Trigger redirect to correct path (as language set in path is default lang and we want to omit it)
$redirect = true;
}
} catch (Exception $e) {
// Trigger "notFound" as setActive() throws Exception if $locale is not valid / available
$next = $this->notFoundHandler;
}
} elseif (!$router->isOmitDefaultLanguage()) {
// Trigger redirect to correct path (as language is not set in path but we don't want to omit default lang)
$redirect = true;
}
// Redirect to route with proper language identifier value set (or omitted)
if ($redirect) {
$path = $router->pathFor($route->getName(), $route->getArguments(), $request->getParams(), $locale->getLanguage());
$uri = $request->getUri()->withPath($path);
return $response->withRedirect($uri);
}
return $next($request, $response);
}
示例6: deleteUser
public function deleteUser(Request $request, Response $response, array $args)
{
$name = $args['name'];
if (empty($name)) {
$this->flash->addMessage('flash', 'No user specified');
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('users'));
}
$user = R::findOne('users', ' email = ? ', [$name]);
if (!empty($user)) {
R::trash($user);
$this->flash->addMessage('flash', "{$name} deleted");
} else {
$this->flash->addMessage('flash', "{$name} User not found");
}
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('users'));
}
示例7: __invoke
public function __invoke(Request $req, Response $res)
{
if ($req->isPost()) {
$adapter = $this->authService->getAdapter();
if ($adapter instanceof ValidatableAdapterInterface) {
$adapter->setIdentity($req->getParam('identity'));
$adapter->setCredential($req->getParam('credential'));
}
$result = $this->authService->authenticate($adapter);
if (!$result->isValid()) {
$this->flash->addMessage('danger', reset($result->getMessages()));
return $res->withRedirect($req->getUri());
}
return $res->withRedirect($this->successUrl);
}
return $this->view->render($res, 'user/login.twig', []);
}
示例8: delete
public function delete(Request $request, Response $response, array $args)
{
$skills = $this->data(MemberSkills::class);
if ($skills->delete((int) $args['id'])) {
$this->addFormAlert('success', 'Item Skill berhasil dihapus.');
} else {
$this->addFormAlert('error', 'Sesuatu terjadi, skill gagal dihapus.');
}
return $response->withRedirect($this->router->pathFor('membership-account'));
}
示例9: __invoke
public function __invoke(ServerRequestInterface $req, Response $res)
{
if ($this->authService->hasIdentity()) {
$identity = $this->authService->getIdentity();
$events = $this->events;
$this->authService->clearIdentity();
$events('trigger', 'logout', $identity, $this->redirectUrl);
}
return $res->withRedirect($this->redirectUrl);
}
示例10: editUser
public function editUser(Request $request, Response $response, array $args)
{
$username = strtolower($args['username']);
if (empty($username)) {
$this->flash->addMessage('flash', 'No user specified');
return $response->withRedirect($this->router->pathFor('profile'));
}
$id = $this->authenticator->getIdentity();
// restrict access to own profile or Admin user
if ($username != strtolower($id['name'])) {
if (strtolower($id['name']) != 'admin') {
$this->flash->addMessage('flash', 'Access Denied');
return $response->withRedirect($this->router->pathFor('profile'));
}
}
if ($username != 'new') {
$user = R::findOrCreate('users', ['name' => $username]);
} else {
$user = R::dispense('users');
}
if ($request->isPost()) {
$data = $request->getParams();
//$username = $request->getParam('username');
$user->import($data, 'fullname,shortdial,longdial,colour,mobile,home');
$user->name = $request->getParam('username');
$password = $request->getParam('password');
if (!empty($password)) {
$pass = password_hash($password, PASSWORD_DEFAULT);
$user->hash = $pass;
}
$id = R::store($user);
$this->flash->addMessage('flash', "{$user->name} updated");
return $response->withRedirect($this->router->pathFor('edituser', ['username' => $username]));
// $member = 'INSERT INTO `users` (`name`, `fullname`, `password`, `hash`, `colour`, `shortdial`, `longdial`, `mobile`, `home`, `ins_mf`, `ins_win`, `health_mf`, `health_win`, `life_mf`, `life_win`, `wealth_mf`, `wealth_win`, `uk_shift`, `atss`) VALUES '
// . "($username, $fullname, :pass, '', 'FAD2F5', $shortdial, $longdial, '', '', '1', '0', '0', '1', '0', '0', '0', '1', '0', '0');
// ";
}
$this->view->render($response, 'user.twig', $user->export());
return $response;
}
示例11: __invoke
/**
* Example middleware invokable class
*
* @param Slim\Http\Request $request PSR7 request
* @param Slim\Http\Response $response PSR7 response
* @param callable $next Next middleware
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function __invoke(Request $request, Response $response, $next)
{
$route = $request->getAttribute('route');
$session = $this->container->session;
$user_id = $session->getVar('userid', 0);
if (!$this->hasAccess($route, $user_id)) {
$router = $this->container->router;
//return $response->withStatus(403);
return $response->withRedirect($router->pathFor('front-index'));
}
$response = $next($request, $response);
return $response;
}
示例12: editUser
public function editUser(Request $request, Response $response, array $args)
{
$username = $args['username'];
if (empty($username)) {
$this->flash->addMessage('flash', 'No user specified');
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('profile'));
}
$username = base64_decode($username);
$id = $this->authenticator->getIdentity();
// restrict access to own profile or Admin role
if ($username != strtolower($id['email'])) {
if (strtolower($id['role']) != 'admin') {
$this->flash->addMessage('flash', 'Access Denied');
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('profile'));
}
}
$user = R::findOne('users', ' email = ? ', [$username]);
if ($user == NULL) {
$user = R::dispense('users');
}
if ($request->isPost()) {
$user->fullname = $request->getParam('userfullname');
$user->email = $request->getParam('username');
$password = $request->getParam('userpassword');
if (!empty($password)) {
$pass = password_hash($password, PASSWORD_DEFAULT);
$user->hash = $pass;
}
$id = R::store($user);
$this->flash->addMessage('flash', "{$user->name} updated");
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('edituser', ['username' => base64_encode($username)]));
}
$expUser['user'] = $user->export();
$expUser['user']['hashemail'] = base64_encode($user['email']);
$this->view->render($response, 'user.twig', $expUser);
return $response;
}
示例13: editUser
public function editUser(Request $request, Response $response, array $args)
{
$username = strtolower($args['username']);
if (empty($username)) {
$this->flash->addMessage('flash', 'No user specified');
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('profile'));
}
$id = $this->authenticator->getIdentity();
// restrict access to own profile or Admin user
if ($username != strtolower($id['name'])) {
if (strtolower($id['name']) != 'admin') {
$this->flash->addMessage('flash', 'Access Denied');
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('profile'));
}
}
if ($username != 'new') {
$user = R::findOrCreate('users', ['name' => $username]);
} else {
$user = R::dispense('users');
}
if ($request->isPost()) {
$data = $request->getParams();
//$username = $request->getParam('username');
$user->import($data, 'fullname,colour,mobile,home');
$user->name = $request->getParam('username');
$password = $request->getParam('password');
if (!empty($password)) {
$pass = password_hash($password, PASSWORD_DEFAULT);
$user->hash = $pass;
}
$id = R::store($user);
$this->flash->addMessage('flash', "{$user->name} updated");
return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('edituser', ['username' => $username]));
}
$this->view->render($response, 'user.twig', $user->export());
return $response;
}
示例14: __invoke
/**
* Execute the middleware.
*
* @param Request $request
* @param Response $response
* @param callable $next
*
* @return Response
*/
public function __invoke(Request $request, Response $response, callable $next)
{
$uri = $request->getUri();
$path = $uri->getPath();
// Add or remove slash as configured
if ($path != '/') {
$path = rtrim($path, '/');
if ($this->addSlash && !pathinfo($path, PATHINFO_EXTENSION)) {
$path .= '/';
}
}
// Redirect
if ($uri->getPath() !== $path) {
return $response->withRedirect($uri->withPath($path), 301);
}
return $next($request, $response);
}
示例15: thumb
/**
* @param string $repo
* @param string $file
* @param int $width
* @param bool $archived
* @param \Slim\Http\Response $response
* @return mixed
*/
function thumb($repo, $file, $width, $archived, $response, $format)
{
$md5 = md5($file);
$file = $md5[0] . '/' . $md5[0] . $md5[1] . '/' . $file;
$path = $repo . ($archived ? 'archive/' : '') . $file;
if (is_readable($path)) {
$path = realpath($path);
$pathParts = pathinfo($path);
if (strpos($pathParts['dirname'], $repo) === 0) {
$cacheDir = $repo . 'thumb/' . ($archived ? 'archive/' : '') . $file;
if (!is_dir($cacheDir)) {
if (!mkdir($cacheDir, 0777, true)) {
return $response->withStatus(403);
}
}
if ($format != 'jpg') {
$cacheFile = $cacheDir . '/' . $width . 'px-' . $pathParts['basename'];
} else {
$cacheFile = $cacheDir . '/' . $width . 'px-' . $pathParts['filename'] . '.jpg';
}
if (!is_readable($cacheFile)) {
$image = new ImageResize($path);
if ($width > $image->getSourceWidth()) {
return $response->withRedirect('/images/' . $file);
} else {
$image->resizeToWidth($width);
if ($format != 'jpg') {
$image->save($cacheFile);
} else {
$image->save($cacheFile, IMAGETYPE_JPEG);
}
}
}
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $cacheFile);
$stream = new \GuzzleHttp\Psr7\LazyOpenStream($cacheFile, 'r');
return $response->withHeader('Content-type', $type)->withBody($stream);
}
}
return $response->withStatus(404);
}