Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect not working when using html format #15

Open
khalidafla opened this issue Aug 22, 2015 · 0 comments
Open

Redirect not working when using html format #15

khalidafla opened this issue Aug 22, 2015 · 0 comments

Comments

@khalidafla
Copy link

When you use view annotation then whatever you return in your controller will be considered as data to the view template, so when using this code:

try {
            $newPage = $this->container->get('acme_blog.page.handler')->post(
                $request->request->all()
            );
            $routeOptions = array(
                'id' => $newPage->getId(),
                '_format' => $request->get('_format')
            );
            return $this->routeRedirectView('api_1_get_page', $routeOptions, Codes::HTTP_CREATED);
 } catch (InvalidFormException $exception) {
            return $exception->getForm();
 }

the view handler will use the view returned by routeRedirectView as the templateData of the annotation view instead of displaying it.

So to prevent this from happening the @view should be removed, but then the function should always return a view like this :

try {
            $newPage = $this->container->get('acme_blog.page.handler')->post(
                $request->request->all()
            );
            $routeOptions = array(
                'id' => $newPage->getId(),
                '_format' => $request->get('_format')
            );
            return $this->routeRedirectView('api_1_get_page', $routeOptions, Codes::HTTP_CREATED);
 } catch (InvalidFormException $exception) {
            return $this->view($exception->getForm(), Codes::HTTP_BAD_REQUEST)
                        ->setTemplate('AcmeBlogBundle:Page:newPage.html.twig');
 }

and it should be working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant