我正在制作自己的名为 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
料青山看我应如是