Reputation: 524
I have a profile page where the url looks like this:
/ClinicalAnnotation/Participants/profile/11
I want to create this /ClinicalAnnotation/Participants/profile/11/submitreview/1
How can I do this with routes?
Also:
On this profile page I have an <a href="">
tag.
<a href="/ClinicalAnnotation/Participants/profile/'.$participantId.'/submitreview/'$medicalRecordReviewId'">Medical Record Review 2 Completed</span>
So I want to create an action in my ParticipantsController.php:
public function submitreview($participantId, $medicalRecordReviewId)
{
echo "Hello";
}
There's also a file called PermissionManagerComponent.php. I have to add the permissions here, something like:
'Controller/ClinicalAnnotation/Participants/submitreview' => 'Controller/ClinicalAnnotation/Participants/profile',
Right now when a User clicks on the a tag, I want to see the word Hello
. Then I'll know what I'm trying to do is working.
Attached is a screenshot of the page and the <a href="">
tag (bottom right portion of the screenshot).
Upvotes: 0
Views: 72
Reputation: 60503
You can use custom route elements to form pretty much any URL you want, something along the lines of this:
Router::connect(
'/ClinicalAnnotation/Participants/profile/:participantId/submitreview/:medicalRecordReviewId',
array(
'controller' => 'Participants',
'action' => 'submitreview',
),
array(
// pass route element values to the controller action
'pass' => array(
'participantId',
'medicalRecordReviewId',
),
// restrict route elements to integer values
'participantId' => '[0-9]+',
'medicalRecordReviewId' => '[0-9]+',
)
);
To generate a link in your templates you can then use the helpers, for example:
echo $this->Html->link('Medical Record Review 2 Completed', array(
'prefix' => null,
'plugin' => false,
'controller' => 'Participants',
'action' => 'submitreview',
'participantId' => $participantId,
'medicalRecordReviewId' => $medicalRecordReviewId,
));
See also
Upvotes: 1