本文整理汇总了PHP中FOS\RestBundle\View\View::createRouteRedirect方法的典型用法代码示例。如果您正苦于以下问题:PHP View::createRouteRedirect方法的具体用法?PHP View::createRouteRedirect怎么用?PHP View::createRouteRedirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\RestBundle\View\View
的用法示例。
在下文中一共展示了View::createRouteRedirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
public function indexAction($name = null)
{
if (!$name) {
$view = View::createRouteRedirect('_welcome');
} else {
$view = View::create(array('name' => $name))->setTemplate(new TemplateReference('LiipHelloBundle', 'Hello', 'index'));
}
return $this->viewHandler->handle($view);
}
示例2: testSetRoute
public function testSetRoute()
{
$routeName = 'users';
$view = View::createRouteRedirect($routeName, array(), Codes::HTTP_CREATED);
$this->assertAttributeEquals($routeName, 'route', $view);
$this->assertAttributeEquals(null, 'location', $view);
$this->assertEquals(Codes::HTTP_CREATED, $view->getResponse()->getStatusCode());
$view->setLocation($routeName);
$this->assertAttributeEquals($routeName, 'location', $view);
$this->assertAttributeEquals(null, 'route', $view);
$view = new View();
$route = 'route';
$view->setRoute($route);
$this->assertEquals($route, $view->getRoute());
}
示例3: onAction
/**
* @param ActionEvent $event
*/
public function onAction(ActionEvent $event)
{
if ($this->getParameterResolver()->resolveApi()) {
return;
}
$form = $event->getForm();
if ($form !== null && !$form->isValid()) {
$view = View::create($form);
} else {
$route = $this->getParameterResolver()->resolveRedirectRoute();
$routeParameters = [];
if ($form !== null) {
$routeParameters = $this->getParameterResolver()->resolveRedirectRouteParameters(is_object($data = $form->getData()) ? $data : null, $this->getParameterResolver()->resolveRedirectRouteParametersForward());
}
$view = View::createRouteRedirect($route, $routeParameters);
}
$event->setView($view);
}
示例4: deletePublication
/**
* @param integer $id
*
* @Delete("/publications/{id}", name="delete_publication", requirements={"id": "\d+"})
*
* @return View
*/
public function deletePublication($id)
{
$publicationRepository = $this->getPublicationRepository();
$publicationManager = $this->getPublicationManager();
$publication = $publicationRepository->find($id);
if (null === $publication) {
return new View(["error" => sprintf("publication %d does not exist", $id)], Codes::HTTP_NOT_FOUND);
}
$publicationManager->delete($publication);
return View::createRouteRedirect("get_publications", [], Codes::HTTP_NO_CONTENT);
}
示例5: routeRedirectView
/**
* Creates a Route Redirect View.
*
* Convenience method to allow for a fluent interface.
*
* @param string $route
* @param mixed $parameters
* @param int $statusCode
* @param array $headers
*
* @return View
*/
protected function routeRedirectView($route, array $parameters = array(), $statusCode = Codes::HTTP_CREATED, array $headers = array())
{
return View::createRouteRedirect($route, $parameters, $statusCode, $headers);
}
示例6: postArticlesAction
/**
* Create a new resource.
*
* @param Request $request
*
* @return View view instance
*
* @ApiDoc()
*/
public function postArticlesAction(Request $request)
{
$form = $this->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
// Note: use FOSHttpCacheBundle to automatically move this flash message to a cookie
$this->get('session')->getFlashBag()->set('article', 'Article is stored at path: ' . $form->getData()->getPath());
// Note: normally one would likely create/update something in the database
// and/or send an email and finally redirect to the newly created or updated resource url
$view = View::createRouteRedirect('hello', array('name' => $form->getData()->getTitle()));
} else {
$view = View::create($form);
$view->setTemplate('LiipHelloBundle:Rest:postArticles.html.twig');
}
// Note: this would normally not be necessary, just a "hack" to make the format selectable in the form
$view->setFormat($form->getData()->format);
return $this->get('fos_rest.view_handler')->handle($view);
}
示例7: deleteAction
/**
* Delete a user
*
* @param Entity\User $user
*
* @return array
*
* @Route(
* "/{id}/delete.{_format}",
* name="zym_user_users_delete",
* defaults={ "_format" = "html" },
* requirements = {
* "id" = "\d+"
* },
* methods={"GET", "POST"}
* )
* @Route(
* "/{id}.{_format}",
* name="zym_user_users_delete_delete",
* defaults={ "_format" = "html" },
* requirements = {
* "id" = "\d+"
* },
* methods={"DELETE"}
* )
*
* @SecureParam(name="user", permissions="DELETE")
*
* @View()
* @ApiDoc(
* description="Delete a user",
* section="Users"
* )
*/
public function deleteAction(Entity\User $user)
{
$request = $this->getRequest();
$form = $this->createForm(new Form\DeleteType(), $user, array('method' => in_array($request->getMethod(), array('DELETE')) ? $request->getMethod() : 'POST'));
$form->handleRequest($request);
if ($form->isValid() || $request->getMethod() == 'DELETE') {
/* @var $userManager Entity\UserManager */
$userManager = $this->get('fos_user.user_manager');
$userManager->deleteUser($user);
return ViewResponse::createRouteRedirect('zym_user_users', array(), Codes::HTTP_OK);
}
return array('user' => $user, 'form' => $form);
}
示例8: routeRedirectView
/**
* Creates a Route Redirect View.
*
* Convenience method to allow for a fluent interface.
*
* @param string $route
* @param mixed $parameters
* @param int $statusCode
* @param array $headers
*
* @return View
*/
protected function routeRedirectView($route, array $parameters = [], $statusCode = Response::HTTP_CREATED, array $headers = [])
{
return View::createRouteRedirect($route, $parameters, $statusCode, $headers);
}
示例9: afterCaptureAction
/**
* @param Request $request
*
* @return Response
*/
public function afterCaptureAction(Request $request)
{
$configuration = $this->requestConfigurationFactory->create($this->paymentMetadata, $request);
$token = $this->getHttpRequestVerifier()->verify($request);
$status = new GetStatus($token);
$this->payum->getGateway($token->getGatewayName())->execute($status);
$resolveNextRoute = new ResolveNextRoute($status->getFirstModel());
$this->payum->getGateway($token->getGatewayName())->execute($resolveNextRoute);
$this->getHttpRequestVerifier()->invalidate($token);
return $this->viewHandler->handle($configuration, View::createRouteRedirect($resolveNextRoute->getRouteName(), $resolveNextRoute->getRouteParameters()));
}
示例10: requestAction
/**
* Request reset user password: show form
*
* @Route(
* ".{_format}",
* name="zym_user_resetting_request",
* defaults={
* "_format" = "html"
* },
* methods={"GET", "POST"},
* options={"expose" = true}
* )
* @Route(
* ".{_format}",
* name="fos_user_resetting_request",
* defaults={
* "_format" = "html"
* },
* methods={"GET", "POST"},
* options={"expose" = true}
* )
* @View()
* @ApiDoc(
* description="Request reset user password.",
* section="User Resetting",
* parameters={
* {"name"="username", "dataType"="string", "required"=true, "description"="Username or Email address", "readonly"=false}
* }
* )
*/
public function requestAction(Request $request)
{
$username = $request->request->get('username');
if ($request->getMethod() == 'POST') {
/** @var UserManager */
$userManager = $this->container->get('fos_user.user_manager');
/** @var $user UserInterface */
$user = $userManager->findUserByUsernameOrEmail($username);
/** @var TranslatorInterface */
$translator = $this->get('translator');
// Invalid username or email
if (null === $user) {
return ViewResponse::create(array('invalid_username' => $username, 'code' => 412, 'message' => $translator->trans('resetting.request.invalid_username', array('%username%' => $username), 'FOSUserBundle')), 412);
}
// User already requested password
if ($user->isPasswordRequestNonExpired($this->container->getParameter('fos_user.resetting.token_ttl'))) {
return ViewResponse::create(array('code' => 409, 'message' => $translator->trans('resetting.password_already_requested', array('%username%' => $username), 'FOSUserBundle')), 409);
}
// Generate confirmation token
if (null === $user->getConfirmationToken()) {
/** @var $tokenGenerator \FOS\UserBundle\Util\TokenGeneratorInterface */
$tokenGenerator = $this->container->get('fos_user.util.token_generator');
$user->setConfirmationToken($tokenGenerator->generateToken());
}
$this->container->get('session')->set(static::SESSION_EMAIL, $this->getObfuscatedEmail($user));
$this->container->get('fos_user.mailer')->sendResettingEmailMessage($user);
$user->setPasswordRequestedAt(new \DateTime());
$userManager->updateUser($user);
// Issue with session not being saved completely before the redirect happens.
$this->container->get('session')->save();
return ViewResponse::createRouteRedirect('zym_user_resetting_check_email', array('_format' => $request->getRequestFormat()));
}
return array();
}
示例11: deleteAction
/**
* Delete a page
*
* @param Entity\Page $page
*
* @return array
*
* @Route(
* "/{id}/delete.{_format}",
* name="zym_content_pages_delete",
* defaults={ "_format" = "html" },
* requirements = {
* "id" = ".+"
* },
* methods={"GET", "POST"}
* )
* @Route(
* "/{id}.{_format}",
* name="zym_content_pages_delete_delete",
* defaults={ "_format" = "html" },
* requirements = {
* "id" = ".+"
* },
* methods={"DELETE"}
* )
*
* @SecureParam(name="page", permissions="DELETE")
*
* @View()
* @ApiDoc(
* description="Delete a page",
* section="Pages"
* )
*/
public function deleteAction(Page $page)
{
$request = $this->getRequest();
$form = $this->createForm(new Form\DeleteType(), $page, array('method' => in_array($request->getMethod(), array('DELETE')) ? $request->getMethod() : 'POST'));
$form->handleRequest($request);
if ($form->isValid() || $request->getMethod() == 'DELETE') {
/* @var $pageManager Entity\PageManager */
$pageManager = $this->get('fos_page.page_manager');
$pageManager->deletePage($page);
return ViewResponse::createRouteRedirect('zym_content_pages', array(), Codes::HTTP_OK);
}
return array('page' => $page, 'form' => $form);
}
示例12: deleteAction
/**
* Delete a group
*
* @param Entity\Group $group
* @return array
*
* @Route(
* "/{id}/delete.{_format}",
* name="zym_user_groups_delete",
* defaults={ "_format" = "html" },
* requirements = {
* "id" = "\d+"
* },
* methods={"GET", "POST"}
* )
* @Route(
* "/{id}.{_format}",
* name="zym_user_groups_delete_delete",
* requirements = {
* "id" = "\d+"
* },
* methods={"DELETE"}
* )
* @View()
*
* @SecureParam(name="group", permissions="DELETE")
*
* @ApiDoc(
* description="Delete a group",
* section="User Groups"
* )
*/
public function deleteAction(Entity\Group $group)
{
$form = $this->createForm(new Form\DeleteType(), $group);
$request = $this->getRequest();
$form->handleRequest($request);
if ($form->isValid() || $request->getMethod() == 'DELETE') {
/* @var $groupManager \FOS\GroupBundle\Entity\GroupManager */
$groupManager = $this->get('fos_user.group_manager');
$groupManager->deleteGroup($group);
return ViewResponse::createRouteRedirect('zym_user_groups', array(), Codes::HTTP_OK);
}
return array('group' => $group, 'form' => $form);
}
示例13: postSuccess
/**
* @param string $resourceRouteName
* @param array $parameters
*
* @return Response
*/
public function postSuccess($resourceRouteName = '', array $parameters = [])
{
return $this->handle(View::createRouteRedirect($resourceRouteName, $parameters, Response::HTTP_CREATED));
}
示例14: afterCaptureAction
/**
* @param Request $request
*
* @return Response
*/
public function afterCaptureAction(Request $request)
{
$configuration = $this->requestConfigurationFactory->create($this->orderMetadata, $request);
$token = $this->getHttpRequestVerifier()->verify($request);
$status = new GetStatus($token);
$this->payum->getGateway($token->getGatewayName())->execute($status);
$resolveNextRoute = new ResolveNextRoute($status->getFirstModel());
$this->payum->getGateway($token->getGatewayName())->execute($resolveNextRoute);
$this->getHttpRequestVerifier()->invalidate($token);
if (PaymentInterface::STATE_NEW !== $status->getValue()) {
$request->getSession()->getBag('flashes')->add('info', sprintf('sylius.payment.%s', $status->getValue()));
}
return $this->viewHandler->handle($configuration, View::createRouteRedirect($resolveNextRoute->getRouteName(), $resolveNextRoute->getRouteParameters()));
}
示例15: postSnapshotsAction
/**
* Create a new snapshot
*
* @ApiDoc(
* resource = true,
* statusCodes = {
* 200 = "Returned when successful",
* 500 = "Error occurred"
* }
* )
*
* @Annotations\View()
*
* @return array
*/
public function postSnapshotsAction()
{
$id = $this->snapshotService->create();
$view = View::createRouteRedirect('get_snapshot', array('id' => $id), Codes::HTTP_CREATED);
$view->setData($this->snapshotService->find($id));
return $view;
}