html->链接没有根据带CakePHP的路由器正确放置链接

时间:2011-07-09 11:48:13

标签: php cakephp cakephp-1.3

我有这个路由器:

Router::connect
(
  ':renting/:model_name/:number_name/',
  array('controller' => 'cars', 'action' => 'view'),
  array(
    'pass' => array('renting', 'model_name', 'number_name'),
    'renting' => 'renting'
  )
);

当我在视图中执行此操作时

$html->link("NAME",
  array(
    'controller' => 'cars',
    'action' => 'view',
    'renting',
    $model_name,
    $number_name
  )
);

我在页面上获得此链接:mypage.com/cars/view/renting/mustang/03212xd

我需要获得mypage.com/renting/mustang/03212xd

我被困在这里。谢谢。注意:muypage.com/renting/mustang/03212xd重定向到我的控制器功能,但在使用$html->link功能时没有。

1 个答案:

答案 0 :(得分:1)

如果您为参数命名,则需要为参数命名:

array(
    'controller'  => 'cars',
    'action'      => 'view',
    'renting'     => 'renting',
    'model_name'  => $model_name,
    'number_name' => $number_name
)

如果:renting始终为'renting',则无需对其进行参数化:

Router::connect('/renting/:model_name/:number_name/',
                array('controller' => 'cars', 'action' => 'view', 'renting'),
                array('pass' => array('model_name', 'number_name')));

$html->link(…, array(
    'controller'  => 'cars',
    'action'      => 'view',
    'renting',
    'model_name'  => $model_name,
    'number_name' => $number_name
));