lithium
lithium copied to clipboard
Router conditional action and param
Expected routing:
/product should route to index action
/product/'any of conditional action'/category should route to desired action with category
/product/category should route to category action with specified category param
Router setup routes.php:
Working routes:
Router::connect('/products', 'Products::index');
Router::connect(
'/products/{:action:add|edit|remove}',
array('controller' => 'Products', 'category' => null)
);
Router::connect('/products/add/{:category}', array('Products::add'));
Router::connect('/products/edit/{:category}', array('Products::edit'));
Router::connect('/products/remove/{:category}', array('Products::remove'));
Router::connect('/products/{:category}', array('Products::category'));
Not working routes:
Router::connect('/products', 'Products::index');
Router::connect(
'/products/{:action:add|edit|remove}/{:category}',
array('controller' => 'Products', 'action' => 'category', 'category' => null)
);
Router::connect('/products/{:category}', array('Products::category'));
Any route that doesn't have add|edit|remove before category param route to index action with correctly passed category param.