douzhuang1900 2016-11-19 09:35
浏览 30

找到了一条命名路由,但匹配失败

I have a strange problem with cakephp 3 and named routes.

  foreach ($categoryProducts as $key => $categoryProduct) {

    /**
     * WORK
     * Result : http://www.website.com/shop/slugshop/products/slugcategory
     */
    $categoryProduct->href_shop_view = Router::url([
      'slug' => $shop->slug,
      'category' => 'some_caractere'.$categoryProduct->slug,
       '_name' => 'viewShopProductsByCategory'
     ]);

    /**
     * Dont't work
     * Result : A named route was found for "viewShopProductsByCategory", but matching failed. 
     */
    $categoryProduct->href_shop_view = Router::url([
      'slug' => $shop->slug,
      'category' => $categoryProduct->slug,
      '_name' => 'viewShopProductsByCategory'
    ]);

  }

And in my routes.php

Router::connect('/shop/:slug/products/:category',
     ['controller' => 'shops','action' => 'products'],
     ['slug'=>'[^\/]+','category'=>'[^\/]+','pass'=>['slug','category'],'_name' => 'viewShopProductsByCategory'
   ]
);

Can you help me please, because i don't found the solution yet and i don't understand my mistake...

Thank you for your help

Edit 1

@ndm Like you can see i use the same named route, with same shop slug and category slug.

But it's like if $categoryProduct->slug return nothing if you don't put somme caractere before

Edit 2

debug($categoryProduct->slug); // Return "e-cigarette"
debug($shopp->slug); // Return "vapoton-com"

If i write directly :

$categoryProduct->href_shop_view = Router::url([
  'slug' => 'vapoton-com',
  'category' => 'e-cigarette',
   '_name' => 'viewShopProductsByCategory'
 ]);

It's work !

Thanks for your help

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ESP8266连接阿里云出现问题
    • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并