Search code examples
typo3url-parameters

TYPO3 Get URL parameters in PHP controller


How do I get the url parameters in my PHP code in TYPO3?

I have link like this

<f:link.page pageUid="138" additionalParams="{myname: Lilly}">Click!</f:link.page>

The page has a controller attached to it, now how do I get the value of the passed parameter to my controller?

I will have to render Views according to the parameter passed.

EDIT

I'm not sure how to go about this problem.

I have a controller which has actions list and show. If the parameters send to show action is all, then all the items should be displayed and similarly the view changes basing on the parameters passed.

My Question is :

  1. How do I pass the parameters and how to catch them in the Controller?
  2. The link to the action controller is showing really long, and looks very ugly. How do I customize the links? Is there something like routes through which I can achieve this?

Solution

  • You just have to use the f:link.action Viewhelper. If you are in list action you could do something like this:

    <f:link.action action="show" arguments="{myArgument: myArgument}">Link</f:link.action>
    

    This should switch the view to the view of the show action.

    If you would need to catch other arguments, you can $this->request->getArguments() to get all arguments, or $this->request->getArgument('myArgument') to get a specific argument in your controller. Note that this will only contain arguments, cleanly sent with a f:link.action Viewhelper, since those arguments are prefixed with the current extension / plugin you are using.

    If you use RealURL, you could provide a configuration to rewrite your URL's to shorter ones.

    Edit:

    If your link needs to point to another page, you just have to add this:

    <f:link.action action="show" arguments="{myArgument: myArgument}" pageUid="myId">Link</f:link.action>