37553

Symfony2: How to get request parameter

I have a route:

professor_identity_edit: path: /professor/{id}/identity defaults: { _controller: FrontBundle:ProfessorIdentity:edit }

How can I get the parameter {id} in twig.html file ?

I already tried app.request.query.get('id') but with no success.

Answer1:

Not a good thing but you can still do. Normally you would pass the info to Twig from the controller like @Maerlyn pointed out.

Get route parameters in Twig.

{{ app.request.attributes.get('_route_params') }}

AND

Gets whole bundle name in Twig.

{{ app.request.attributes.get("_controller") }}

Get route name in Twig.

{{ app.request.attributes.get('_route') }}

Answer2:

I found the solution:

{{ app.request.attributes.get('_route_params')['id'] }}

Recommend

  • How do I convert this Access Query to mySQL query?
  • Calling a subclass constructor from a superclass
  • Time Complexity of Nested For Loop with If
  • Error Code MySQL Workbench: 1215 Cannot add foreign key constraint
  • Error in regex formulation for web scraping in python
  • pthreads and signal handling C ending early
  • Create a top down parser based on a custom language
  • Stripe payment gateway create recurring payment using PayumBundle
  • Scatter plot with factor on horizontal axis
  • Use custom column in Sonata Admin list
  • Symfony2 Form is always empty after submitting
  • Symfony 2 error page response
  • Cannot get the UserManager class
  • Unable to decode certificate at client new X509Certificate2()
  • Needing to do .toArray() to get output of mongodb .find() on key name not value
  • Why does access(2) check for real and not effective UID?
  • Checking free space on FTP server
  • Django: Count of Group Elements
  • Is calc() supported in html email?
  • req.body is undefined - nodejs
  • Fetching methods from BroadcastReceiver to update UI
  • How would I use PHP exceptions to define a redirect?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • script to move all files from one location to another location
  • ILMerge & Keep Assembly Name
  • ORA-29908: missing primary invocation for ancillary operator
  • Why winpcap requires both .lib and .dll to run?
  • Akka Routing: Reply's send to router ends up as dead letters
  • GridView Sorting works once only
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Is there a mandatory requirement to switch app.yaml?
  • How to get icons for entities from eclipse?
  • WPF Applying a trigger on binding failure
  • log4net write single file for each call to log.info
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Getting error when using KSoap library to consume .NET web services
  • coudnt use logback because of log4j
  • JaxB to read class hierarchy