dougudu3564 2012-12-04 17:34
浏览 15

链接和路由问题

In my view I have the following link:

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

I expect the link to output: http://example.com/shows/3/articles/6

My route looks like this:

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

Instead my link is returned like this: http://example.com/articles/6/category:shows/page:3

How do I get this to display properly without using an absolute URL? Is this an issue with my routing, view, link HTML Helper or a combination of the 3? I think the issue is with how the link helper parses the URL but I'm not sure how to change that.

If I enter manually into my browser the url http://example.com/shows/3/articles/16, the correct page is displayed.

I looked into named parameters but that doesn't seem to accomplish what I want either.

  • 写回答

1条回答 默认 最新

  • doubei8541 2013-01-16 10:25
    关注

    You need to include all your params in your pass.

    So your route should look like,

    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 ;)
        )
    );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM