Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[book] fixes typo about redirect status codes in the controller chapter.#6220

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
xabbuh merged 1 commit intosymfony:2.7fromhhamon:fix-controller-redirect
Feb 6, 2016
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionbook/controller.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -438,7 +438,7 @@ If you want to redirect the user to another page, use the ``redirectToRoute()``
return $this->redirectToRoute('homepage');

// redirectToRoute is equivalent to using redirect() and generateUrl() together:
// return $this->redirect($this->generateUrl('homepage'), 301);
// return $this->redirect($this->generateUrl('homepage'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not sure this is a typo. The default value of the second argument ofredirect is302:

protectedfunctionredirect($url,$status =302)    {returnnewRedirectResponse($url,$status);    }

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

By default, bothredirect() andredirectToRoute() do a302 not a301, which must be explicitely pass to the function.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

class Controller{/**     * Returns a RedirectResponse to the given URL.     *     * @param string $url    The URL to redirect to     * @param int    $status The status code to use for the Response     *     * @return RedirectResponse     */protectedfunctionredirect($url,$status =302)    {returnnewRedirectResponse($url,$status);    }/**     * Returns a RedirectResponse to the given route with the given parameters.     *     * @param string $route      The name of the route     * @param array  $parameters An array of parameters     * @param int    $status     The status code to use for the Response     *     * @return RedirectResponse     */protectedfunctionredirectToRoute($route,array$parameters =array(),$status =302)    {return$this->redirect($this->generateUrl($route,$parameters),$status);    }}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

you are right@hhamon, but to have an example of a status code is not bad imo, what about changing301 to302 ??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Would you like to open a pull request for that change? By the way, I do not think we need a complete example for that, but we could add a note talking about the fact that redirects by default are responses with a 302 status code but that you can change them through the last parameter of both methods.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sure! Will do ;)

}

.. versionadded:: 2.6
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp