Issue
I'm building my link like this:
$this->Html->link(
$this->Icon->fa('plus'),
['controller' => 'Questions', 'action' => 'add', $questionnaire->id],
[
'title' => 'Add'
]
);
This creates the desired icon on my browser, with this link:
<host>/questionnaire/questions/add/2
On the "other side", by using for example
$this->request->getParam('action')
I can correctly get "add" as a value.
But how can I access the 2, so the last part of the url?
I've tried with
$this->request->getQueryParams()
and it returns an empty array.
Solution
That depends on your connected routes. If there is a corresponding route that has a route element defined for that value, eg
/questionnaire/questions/add/:id
then you could get the value via that element name, getParam('id').
If the corresponding route does not have a dedicated named element for that value, but instead a *, which is the default for fallback routes connected via fallbacks(), then it will land in the pass parameter, getParam('pass'), which is an array of trailing values, and your value would sit at index 0.
See also
- Cookbook > Request & Response Objects > Request Parameters
- Cookbook > Routing > Route Elements
- Cookbook > Routing > Passed Arguments
Answered By - ndm Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.