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