在cakephp中对同一个视图文件创建两个操作?

btxsgosb  于 2022-11-11  发布在  PHP
关注(0)|答案(1)|浏览(133)

我有一个个人资料页面,其URL如下所示:/ClinicalAnnotation/Participants/profile/11
我想创建这个/ClinicalAnnotation/Participants/profile/11/submitreview/1
如何对路线执行此操作?

**另外:**在此个人资料页面上,我有一个<a href="">标记。

<a href="/ClinicalAnnotation/Participants/profile/'.$participantId.'/submitreview/'$medicalRecordReviewId'">Medical Record Review 2 Completed</span>

所以我想在ParticipantsController.php中创建一个动作:

public function submitreview($participantId, $medicalRecordReviewId)
{
    echo "Hello";
}

还有一个名为PermissionManagerComponent.php的文件。我必须在此处添加权限,类似于:

'Controller/ClinicalAnnotation/Participants/submitreview' => 'Controller/ClinicalAnnotation/Participants/profile',

现在,当用户点击a标签时,我希望看到单词Hello,这样我就知道我正在尝试做的事情是有效的。
附件是该页面的屏幕截图和<a href="">标签(屏幕截图的右下部分)。

laximzn5

laximzn51#

您可以使用自定义路由元素来形成几乎任何您想要的URL,大致如下:

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]+',
    )
);

要在模板中生成链接,您可以使用帮助器,例如:

echo $this->Html->link('Medical Record Review 2 Completed', array(
    'prefix' => null,
    'plugin' => false,
    'controller' => 'Participants',
    'action' => 'submitreview',
    'participantId' => $participantId,
    'medicalRecordReviewId' => $medicalRecordReviewId,
));

另请参阅

*操作手册〉开发〉路由〉将参数传递给操作
*操作手册〉开发〉工艺路线〉反向工艺路线
*Cookbook〉视图〉帮助程序〉HtmlHelper〉链接()

相关问题