Jump to content
Larry Ullman's Book Forums

Yii Routes '<Controller:\W+>/<Id:\D+>'=>'<Controller>/View'


Recommended Posts

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 404
The 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?

Link to post
Share on other sites

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!

Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...