为了账号安全,请及时绑定邮箱和手机立即绑定

Cakephp 2 插件路由在表单操作中不起作用

Cakephp 2 插件路由在表单操作中不起作用

PHP
GCT1015 2023-03-04 18:10:31
我正在制作自己的名为 Rma 的 cakephp 2 插件,并为此插件制作了一些路由。当我想制作一个链接到编辑页面的表单时,该链接与我的路由文件中的链接不同。在浏览器中,我的路由正常工作,但是当我更改表单操作或回显 Html 链接时,cakephp 会生成不同的链接。该代码echo $this->Html->url(array('plugin' => 'Rma', 'controller' => 'RmaRequests', 'action' => 'edit', 2));为我提供了以下 url:'/Rma/RmaRequests/edit/2',而路由文件中的 url 为'/rma/edit/:id'。Cakephp 给了我错误的网址。这是我在插件配置文件夹中的 routes.php (app/Plugin/Rma/Config/routes.php):Router::connect('/rma/new', [    'plugin' => 'Rma',    'controller' => 'RmaRequests',    'action' => 'add']);Router::connect('/rma/edit/:id', [    'plugin' => 'Rma',    'controller' => 'RmaRequests',    'action' => 'edit'],    array(        // order matters since this will simply map ":id" to        // $articleId in your action        'pass' => array('id'),        'id' => '[0-9]+'    ));Router::connect('/rma/new/:id/', array(    'plugin' => 'Rma', 'controller' => 'RmaRequestProducts', 'action' => 'add'),    array(        // order matters since this will simply map ":id" to        'pass' => array('id'),        'id' => '[0-9]+'    ));我也尝试将路由放在我的应用程序 routes.php 中,但这仍然没有解决问题。这是我在 app/Config/bootstrap.php 中加载插件的方式: CakePlugin::load('Rma', array('routes' => true, 'bootstrap' => true));有什么我忘记了或者我做错了什么吗?我正在使用 CakePHP 版本 2.5.1
查看完整描述

1 回答

?
料青山看我应如是

TA贡献1772条经验 获得超7个赞

答案,thnx to @ndm in the comments:

Url 有一个名为 id 的命名参数。代替: echo $this->Html->url(array('plugin' => 'Rma', 'controller' => 'RmaRequests', 'action' => 'edit', 2));

一定是

echo $this->Html->url(array('plugin' => 'Rma', 'controller' => 'RmaRequests', 'action' => 'edit', 'id'=> 2));


查看完整回答
反对 回复 2023-03-04
  • 1 回答
  • 0 关注
  • 71 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信