我对cakephp 3和命名路线有一个奇怪的问题。
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'
]);
}
在我的routes.php中
Router::connect('/shop/:slug/products/:category',
['controller' => 'shops','action' => 'products'],
['slug'=>'[^\/]+','category'=>'[^\/]+','pass'=>['slug','category'],'_name' => 'viewShopProductsByCategory'
]
);
你能帮助我吗,因为我还没有找到解决方案而且我不理解我的错误......
感谢您的帮助
修改1
@ndm就像你可以看到我使用相同的命名路线,同一个商店slug和类别slug。
但是,如果 $ categoryProduct-> slug ,如果你没有在之前添加somme caractere,则会返回任何内容
修改2
debug($categoryProduct->slug); // Return "e-cigarette"
debug($shopp->slug); // Return "vapoton-com"
如果我直接写:
$categoryProduct->href_shop_view = Router::url([
'slug' => 'vapoton-com',
'category' => 'e-cigarette',
'_name' => 'viewShopProductsByCategory'
]);
这是工作!
感谢您的帮助