Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Request::getPathInfo() sometimes returns "_fragment" #7138

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

Closed
XWB opened this issue Feb 20, 2013 · 7 comments
Closed

Request::getPathInfo() sometimes returns "_fragment" #7138

XWB opened this issue Feb 20, 2013 · 7 comments

Comments

@XWB
Copy link
Contributor

XWB commented Feb 20, 2013

Imagine the following route:

user:
    pattern: /profile/{id}

Now you're visiting this page and you want to print the page url:

{{ app.request.pathInfo }}

Request::getPathInfo() returns /profile/1337 as expected.

Now I'm rendering a fragment in the same template:

{{ app.request.pathInfo }}

{{ render(controller('MyBundle:Controller:action')) }}

Request::getPathInfo() returns _fragment.

@stof
Copy link
Member

stof commented Feb 20, 2013

This is entirely expected: when rendering a template in a subrequest, app.request will give you the Request object of the subrequest (it always give you the current one). And when using the controller notation, the url of the subrequest will be something like /_fragment?_controller=...

@bamarni
Copy link
Contributor

bamarni commented Feb 20, 2013

I think it's a valid concern, this is clearly a limitation of the framework, there are simple use cases such highlighting the current tab of a menu which cannot be achieved in some situations because of this.

Maybe the notion of parent request should be introduced?

@stof
Copy link
Member

stof commented Feb 20, 2013

We cannot have a notion of parent request, as the fragments are not always rendered from inside the handling of a parent request.
When using ESI or HInclude, the fragment request is coming from Varnish (for ESI) or the client browser (for HInclude) and is the main request of this call to your webserver hosting the Symfony app.
If your subrequest need to know the pathinfo of the main request using it, you need to include the pathinfo in the data passed to the subrequest.

@bamarni
Copy link
Contributor

bamarni commented Feb 20, 2013

I agree with you, in some situations there is no parent request, I'm
talking about sub-requests generated by symfony on the same process.
Le 20 févr. 2013 18:34, "Christophe Coevoet" [email protected] a
écrit :

We cannot have a notion of parent request, as the fragments are not always
rendered from inside the handling of a parent request.
When using ESI or HInclude, the fragment request is coming from Varnish
(for ESI) or the client browser (for HInclude) and is the main request of
this call to your webserver hosting the Symfony app.
If your subrequest need to know the pathinfo of the main request using it,
you need to include the pathinfo in the data passed to the subrequest.


Reply to this email directly or view it on GitHubhttps://github.com//issues/7138#issuecomment-13845015.

@XWB
Copy link
Contributor Author

XWB commented Feb 20, 2013

This is entirely expected

I see. It might be useful to put this in the s2.2 changelog file, because getPathInfo() always returns the parent route in s2.1 and I had no idea this was changed.

@stof
Copy link
Member

stof commented Feb 20, 2013

app.request always returned the current request

@fabpot fabpot closed this as completed in 069d030 Feb 23, 2013
fabpot added a commit that referenced this issue Feb 23, 2013
* 2.2:
  Defined stable version point of Doctrine.
  [HttpFoundation] Remove Cache-Control when using https download via IE<9 (fixes #6750)
  Update composer.json
  [Form] Fixed TimeType not to render a "size" attribute in select tags
  [Form] Added test for "label" option to accept the value "0"
  Expanded fault-tolerance for unusual cookie dates
  Fix docblock type
  [Form] Fixed "label" option to accept the value "0"
  Added greek translation
  merged branch jfcixmedia/2.1 (PR #5838)
  added a note about a BC break for the path info of sub-request (closes #7138)
  [DomCrawler] lowered parsed protocol string (fixes #6986)
  [FrameworkBundle] Fix a BC for Hinclude global template
  [HttpKernel] fixed locale management when exiting sub-requests
  fixed HInclude renderer (closes #7113)
  Removed some leaking deprecation warning in the Form component
  [HttpKernel] hinclude fragment renderer must escape URIs properly to return valid html

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/composer.json
	src/Symfony/Component/Security/composer.json
@vinhne
Copy link

vinhne commented Jul 22, 2015

zzzzz

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

5 participants