ruby on rails - Cake PHP Routing issue -
i need special routing in cake, can't life of me figure out.
i have shop controller @ /shop
, format of url be:
/shop/:category/:sub_category/:product_slug
in routing need send each part of url different action, example if url /shop/cakes
go category action of shop.
however if url /shop/cakes/macaroons
or /shop/cakes/fairy
go sub category action on shop controller.
and the same again /shop/cakes/macaroons/pistachio
go product action on shop controller.
how go in routing? starting
router::connect('/shop/:category/:sub_category/:product_slug' ...
or way off mark? thanks.
you'll need 3 routes, in order:
router::connect( '/shop/:category/:sub_category/:product_slug', array('controller'=>'shops','action'=>'product'), array('pass'=>array('product_slug')) ); // dispatches shopscontroller::product( $product_slug ) /* * reverse route: * array( * 'controller'=>'shops','action'=>'product', * 'category'=>$some_category', 'sub_category'=>$some_sub_category * 'product_slug'=>$some_product_slug * ) */ router::connect( '/shop/:category/:sub_category', array('controller'=>'shops','action'=>'subcategory'), array('pass'=>array('sub_category')) ); // dispatches shopscontroller::subcategory( $sub_category ) /* * reverse route: * array( * 'controller'=>'shops','action'=>'product', * 'category'=>$some_category', 'sub_category'=>$some_sub_category * ) */ router::connect( '/shop/:category', array('controller'=>'shops','action'=>'category'), array('pass'=>array('category')) ); // dispatches shopscontroller::category( $category ) /* * reverse route: * array( * 'controller'=>'shops','action'=>'product', * 'category'=>$some_category' * ) */
Comments
Post a Comment