Reputation: 1903
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 :
routes
through which I can achieve this?Upvotes: 1
Views: 9921
Reputation: 872
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>
Upvotes: 2
Reputation: 5132
If you need more advanced view helpers, there's also the VHS extension http://fedext.net/viewhelpers/vhs.html
Upvotes: 1
Reputation: 55798
For fully automatic support of actions you would need to use f:link.action
viewhelper however as you discovered yet - it creates too long sets of params (including controller etc.)
The best option in such case is mentioned f:link.page
VH however you need to put more effort to find proper actions.
You have several options:
show
action as default one, second - list
action. And then you can use simplified params.bootstrap
your plugin with different default action - depending on TS conditions (if param x exist bootstrap with show, else with list)Use one action for both views, and render a standalone view as a result:
public function show2Action() {
$view = t3lib_div::makeInstance('Tx_Fluid_View_StandaloneView');
if (t3lib_div::_GP('myname') == 'Lilly') {
$view->setTemplatePathAndFilename(t3lib_extMgm::extPath('yourext') . '/Resources/Private/Templates/Some/Show.html');
$view->assign('message', 'Hello ' . t3lib_div::_GP('myname'));
} else {
$view->setTemplatePathAndFilename(t3lib_extMgm::extPath('yourext') . '/Resources/Private/Templates/Some/List.html');
$view->assign('message', 'Enter your name');
}
return $view->render();
}
Don't forget to validate your data fetched with _GP
.
Upvotes: 1