简体   繁体   中英

How call specific action using only attributes without using controller and action name in link CAKEPHP 2.x

I'm trying use only category name to get all products relating to that category from Category controller without mentioning controller name in link

products is my default controller.

Router::connect('/', array('controller' => 'products', 'action' => 'index'));

i want to get product of any category by this link

website.com/category_name

while now i'm able to getting in this way

website.com/categories/find_products/category_name 

so kindly suggest me how to use proper mapping/routing to do this.

You router should looks like:

Router::connect('/:category_name', array('controller' => 'categories', 'action' => 'find_products'));

Then in your action you can read your param from:

$this->params['category_name'];

Important thing is that you have to place this route as last in your routes.php file, because it will be catch all requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM