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

Keep query params on redirect#27482

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

Closed

Conversation

@lfjeff
Copy link

@lfjefflfjeff commentedJun 3, 2018
edited by nicolas-grekas
Loading

Added optional $keepQueryParams to redirect() and redirectToRoute() methods.

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#...
LicenseMIT
Doc PRsymfony/symfony-docs#...

Jeff Groves added2 commitsJune 3, 2018 15:49
…) and redirectToRoute() methodsI liked the addition of $keepQueryParams to the redirectAction() method,but I thought it would be an even  more useful addition to theControllerTraits redirect() and redirectToRoute() methods.
4.1.0
-----

* Added optional $keepQueryParams argument to redirect() and redirectToRoute() methods

Choose a reason for hiding this comment

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

should be moved in the 4.2 section

@nicolas-grekasnicolas-grekas added this to thenext milestoneJun 4, 2018
* @final
*/
protectedfunctionredirect(string$url,int$status =302):RedirectResponse
protectedfunctionredirect(string$url,int$status =302,bool$keepQueryParams =false):RedirectResponse
Copy link
Contributor

Choose a reason for hiding this comment

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

As this function accepts a URL and not a route, I don't see the usefulness of this feature to be honest. When generating the URL, you can already use the url generator to add the current query string based on$request->query->all();.

yceruto, ro0NL, sroze, jochenmanz, and einenlum reacted with thumbs up emoji
Copy link
Author

@lfjefflfjeffJun 4, 2018
edited
Loading

Choose a reason for hiding this comment

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

redirect() is called by redirectToRoute() and I wanted to keep things consistent with both functions and with fix#26281. Also, the way I did things it will append the old query params to the redirect url (which might have its own query params). I basically borrowed the code from urlRedirectAction() and gave these functions the same $keepQueryParams option.

I had a bunch of code where I was appending query params before calling redirect() or redirectToRoute() and it just made sense to move the logic into the function.

Copy link
Member

Choose a reason for hiding this comment

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

if you callredirectToRoute, you can pass extra params to the url generator, and it will put them in the query string.

So IMO, this is not needed (the redirect controller does not give you the control of the arguments which is why it needed to add this feature)

fabiofdsantos and einenlum reacted with thumbs up emoji
@nicolas-grekas
Copy link
Member

@lfjeff OK to close? If you think the doc could be improved, PR welcome on it of course.

sroze and einenlum reacted with thumbs up emoji

@lfjeff
Copy link
Author

OK with me to close. This is my first Symfony contribution, so I'm not sure where the relevant doc for this feature is located.

protectedfunctionredirect(string$url,int$status =302,bool$keepQueryParams =false):RedirectResponse
{
if ($keepQueryParams) {
$qs =$this->container->get('request_stack')->getCurrentRequest()->getQueryString();
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe you can rename $qs to $queryString ?

if ($keepQueryParams) {
$qs =$this->container->get('request_stack')->getCurrentRequest()->getQueryString();
if ($qs) {
if (false ===strpos($url,'?')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it will be more readable with a ternary

@javiereguiluz
Copy link
Member

Closing as explained in favor ofsymfony/symfony-docs#10373. Thanks!

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestSep 21, 2018
…(javiereguiluz)This PR was merged into the 2.8 branch.Discussion----------Mentioned how to redirect and maintain the query stringThisfixessymfony/symfony#27482.Commits-------71d6ab1 Mentioned how to redirect and maintain the query string
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

+2 more reviewers

@linaorilinaorilinaori left review comments

@ronfroyronfroyronfroy left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

7 participants

@lfjeff@nicolas-grekas@javiereguiluz@stof@linaori@ronfroy@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp