Jump to content
Larry Ullman's Book Forums

Quick Routing Question


Recommended Posts

Hi

 

Just wondered about this. Obviously you can view an inidividual record in Yii using the actionView() method. So for an example

 

www.example.com/item/1

 

Would return that record. For SEO purposes it would be nice to load in the url

 

www.example.com/item/1/items-name

 

A couple of things for this. 1) Should I store a slug hyphenating the individual items name?

 

Secondly is it just a case of using something like this in your routes

 

'<controller:\w+>/<id:\d+>/<title:\^[a-zA-Z-]+>'=>'<controller>/view',

 

I'm not sure if that is a Regex problem or not. I did check it out in a regex tester and it seems to work, but I get "The system is unable to find the requested action "1". when i try to load the page with a title.

 

 

On the other hand

'<controller:\w+>/<id:\d+>/<title:\w+>'=>'<controller>/view',

 

allows me to find

 

www.example.com/item/1/itemsname

 

Which is half way there. I'm just not 100% sure what my problem is currently.

 

I should also mention that the title "items-name" isn't important to me within a query. I'd be happy to just use the id to find a record. The title was purely for SEO/aesthetics.

 

Thanks

 

Jonathon

Link to post
Share on other sites

So,

 

I used this rule in my config

'item/<id:\d+>/<title>' => 'item/view',

 

Which works. The title placeholder accepts any characters. I am purely using this rule for user readability. Is that approach ok? I would assume so purely because the actionView() only accepts the $id. However if somebody could confirm this for me that would be great.

 

I'm still a little unsure why when i try

 

<title:\^[a-zA-Z-]+>

 

It fails

  • Upvote 1
Link to post
Share on other sites

Hey Larry,

 

I just left it as

'item/<id:\d+>/<title>' => 'item/view',

 

Which currently was ok, as I was just experimenting. However, I wasn't sure why

 

'item/<id:\d+>/<title:\^[a-zA-Z-]+>' => 'item/view',

 

wasn't working. If you could let me know if there are any obvious errors with this that would be great as i'd prefer to use a regex to monitor what's in the url. That being said, i'll refer back to my last comment. As i'm purely using the title for decoration purposes, do I even need the regex as nothing in the url is using within the controller?

 

Thanks for getting back to me

  • Upvote 1
Link to post
Share on other sites
  • 1 year later...

Hi

 

Just wondered about this. Obviously you can view an inidividual record in Yii using the actionView() method. So for an example

 

www.example.com/item/1
Would return that record. For SEO purposes it would be nice to load in the url

 

www.example.com/item/1/items-name
A couple of things for this. 1) Should I store a slug hyphenating the individual items name?

 

Secondly is it just a case of using something like this in your routes

 

'<controller:\w+>/<id:\d+>/<title:\^[a-zA-Z-]+>'=>'<controller>/view',
I'm not sure if that is a Regex problem or not. I did check it out in a regex tester and it seems to work, but I get "The system is unable to find the requested action "1". when i try to load the page with a title.

 

 

On the other hand

'<controller:\w+>/<id:\d+>/<title:\w+>'=>'<controller>/view',
allows me to find

 

www.example.com/item/1/itemsname
Which is half way there. I'm just not 100% sure what my problem is currently.

 

I should also mention that the title "items-name" isn't important to me within a query. I'd be happy to just use the id to find a record. The title was purely for SEO/aesthetics.

 

Thanks

 

Jonathon

 

 

I wonder how this works for Google analyzing your website.

 

What happens when Google analyzes

 

item/1/gun44

item/2/gun44

item/2-gun 44

 

instead of

 

item/gun44-1

item/gun44-2

item/gun44-3

 

 

I used the 2nd method but the problem is you have to show list all the routes for other item controller actions in the config main.php so they can work.

 

But if you done users you wouldn't want to go

 

user/1

 

because you would be giving away there ID. And to solve the problem of listing extra routes in the main config file to have other user controller actions run. You could just do this

 

user/member/edward

 

instead of

 

user/edward

 

What eBay and their rival eBid did:

 

http://www.ebay.com/itm/Star-Wars-Vintage-Collection-2010-DACK-RALTER-REBEL-PILOT-VC07-MOC/261422612497   (Looks like you may be onto something Jonathon)

 

http://us.ebid.net/for-sale/star-wars-vintage-collection-79-darth-sidious-124699732.htm

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...