Edward 108 Posted July 20, 2013 Report Share Posted July 20, 2013 I have a slight problem I want to be able to load items via name or numerical id, yii is already set to work with numerical id through '<controller:\w+>/<id:\d+>'=>'<controller>/view' but what if i pass a unique string instead to the view page how could i get that to work for example: mywebsite/item/babolat-aerodrive-2013-nadal-rafa-3 I have tried to make some of my own customizations but they have failed to work and i received the following error message: Error 404The system is unable to find the requested action "babolat-aerodrive-2013-nadal-rafa-3". Is there someone that may know how to deal with such a situation? Quote Link to post Share on other sites
Edward 108 Posted July 21, 2013 Author Report Share Posted July 21, 2013 After some peaceful mediation: '<controller:item>/<id:\S+>'=>'item/view', As you can see this will strictly work for only the item controller and will not interfere with others. I also used \S because this means not whitespace, if I use /w it will cover all word characters but not the hypen "-" which I need. You also need to add pages in item you need to access in config/main.php routes otherwise the above route will always send you to the view page. 'item/create'=>'item/create', Have a nice weekend everybody! Quote Link to post Share on other sites
Larry 428 Posted July 22, 2013 Report Share Posted July 22, 2013 Excellent. Kudos for figuring that out and thanks for sharing. Here's to peaceful meditation! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.