2012-12-04 209 views
1

在我看来,我有以下链接:链路和路由问题

<?php echo $this->Html->link($article['Article']['title'], array('category' => $article['Page']['Category']['directory'], 'page' => $article['Article']['page_id'], $article['Article']['id'])); ?> 

我期望的链接输出:http://example.com/shows/3/articles/6

我的路线是这样的:

Router::connect(
    '/:category/:page/:controller/:id', 
    array('action' => 'view'), 
    array(
     'pass' => array('id'), 
     'page' => '[0-9]+', 
     'id' => '[0-9]+', 
     'category' => 'shows|music|games|books|hobbies', 
    ) 
); 

而是我的链接返回这样的:http://example.com/articles/6/category:shows/page:3

如何在不使用绝对URL的情况下正确显示此信息?这是我的路由,查看,链接HTML助手还是3个组合的问题?我认为问题在于链接助手如何解析URL,但我不知道如何更改。

如果手动输入我的浏览器的网址http://example.com/shows/3/articles/16,将显示正确的页面。

我看着命名参数,但似乎并没有达到我想要的。

回答

0

您需要在您的pass中包含所有参数。

所以你的路线应该是什么样子,

Router::connect(
    '/:category/:page/:controller/:id', 
    array('action' => 'view'), 
    array(
     'pass' => array('category','page','id'), // added all passed params here 
     'category' => 'shows|music|games|books|hobbies' 
     'page' => '[0-9]+', 
     'id' => '[0-9]+' 
     // Just re-ordered to match your route ;) 
    ) 
);