本文整理汇总了PHP中Symfony\Component\HttpFoundation\RedirectResponse::setContent方法的典型用法代码示例。如果您正苦于以下问题:PHP RedirectResponse::setContent方法的具体用法?PHP RedirectResponse::setContent怎么用?PHP RedirectResponse::setContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\RedirectResponse
的用法示例。
在下文中一共展示了RedirectResponse::setContent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postPostEdit
public function postPostEdit($request, $response, $args)
{
if (!$this->app->auth()->isLoggedIn()) {
$response = new RedirectResponse('/unauthorised');
return $response;
}
$template = $this->twig->loadTemplate('post/edit.twig');
$validator = new \Valitron\Validator(array('title' => $this->app->input()->post('title'), 'body' => $this->app->input()->post('body'), 'status' => $this->app->input()->post('status')));
$validator->rule('required', ['title', 'body', 'status']);
$validator->rule('integer', ['status']);
if ($validator->validate()) {
$post = \Model::factory('\\App\\Models\\Post')->find_one($args['id']);
if ($post) {
$post->title = $this->app->input()->post('title');
$post->body = $this->app->input()->post('body');
$post->updated_at = date('Y-m-d H:i:s');
$post->status = $this->app->input()->post('status');
if ($post->save()) {
$response = new RedirectResponse('/');
return $response;
} else {
$response->setContent($template->render(['errors' => [['Unable to edit post']], 'input' => $this->app->input()->all('post')]));
}
} else {
$response->setContent($template->render(['errors' => $validator->errors(), 'input' => $this->app->input()->all('post')]));
return $response;
}
} else {
$response->setContent($template->render(['errors' => $validator->errors(), 'input' => $this->app->input()->all('post')]));
return $response;
}
}
示例2: postLogin
public function postLogin($request, $response, $args)
{
$template = $this->twig->loadTemplate('login.twig');
$validator = new \Valitron\Validator(array('email' => $this->app->input()->post('email'), 'password' => $this->app->input()->post('password')));
$validator->rule('required', ['email', 'password']);
$validator->rule('email', 'email');
$validator->rule('lengthMin', 'password', 6);
if ($validator->validate()) {
if ($this->app->auth()->login($this->app->input()->post('email'), $this->app->input()->post('password'))) {
$response = new RedirectResponse('/');
return $response;
} else {
$response->setContent($template->render(['errors' => [['Unable to login, username and/or password may be incorrect']], 'input' => $this->app->input()->all('post')]));
return $response;
}
} else {
$response->setContent($template->render(['errors' => $validator->errors(), 'input' => $this->app->input()->all('post')]));
return $response;
}
}
示例3: onAuthorizationRequest
/**
* @param GetResponseForAuthenticationEvent $event
*/
public function onAuthorizationRequest(GetResponseForAuthenticationEvent $event)
{
if ($event->getResponse() !== null) {
return;
}
$request = $event->getRequest();
// Only act on response_type=token
$responseType = $request->get("response_type");
if ($responseType !== "token") {
return;
}
// Verify that implicit grants are allowed
$client = $event->getClient();
if (!$client->isAllowedGrantType("implicit")) {
return;
}
$user = $event->getUser();
$content = $this->getResponseContent($client, $user);
$redirectUri = $request->get("redirect_uri");
$state = $request->get("state");
$queryData = ["state" => $state];
$queryString = http_build_query($queryData);
$url = $redirectUri . "?" . $queryString;
$response = new RedirectResponse($url);
$response->setContent(json_encode($content));
$event->setResponse($response);
}
示例4: redirectTo
public function redirectTo(string $route, array $routeParams = []) : RedirectResponse
{
$url = $this->router->generate($route, $routeParams, true);
$response = new RedirectResponse($url);
$response->setContent(sprintf('<!DOCTYPE html><html><head></head><script>window.location.href = "%s";</script></html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8')));
return $response;
}