Yii Framework Forum: SEO Friendly - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

SEO Friendly Approach generating the url Rate Topic: -----

#1 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 20 March 2012 - 02:34 PM

I've a database with cities. And every city belongs to a municipality and a municipality belongs to a province. To create nice SEO friendly URLs I've saved a slug into my database. For example: noord-holland-wijdemeren-s-graveland. Where province is noord-holland, municipality wijdemeren and city s-graveland.

In the urlManager i created the rule:
'city/<id:\d+>/<province:[\w\-]+>/<municipality:[\w\-]+>/<city:[\w\-]+>' => 'city/view',


So i can go to http://domain.dev/ci...en/s-graveland/ and the id 1 will make sure i get the right city.

So far so good! But how i can create the url in my website using CHtml:link that goes to the URL just mentioned. Because the slug in the database is saved as 'noord-holland-wijdemeren-s-graveland' and not 'noord-holland/wijdemeren/s-graveland'.

So my city record looks like this in the table:
id_city	country_id	province	municipality	city	sluge
1	1	Noord-Holland	Wijdemeren	's-Graveland	noord-holland-wijdemeren-s-graveland


Any ideas/hints/comments on my approach?
0

#2 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 756
  • Joined: 02-February 09

Posted 21 March 2012 - 05:21 AM

You are saying that you do not save province, municipality and city and at the same time your table contains province, municipality and city so finally do you save them separately in your table or not? If you do it is easy just pass them as parameters to chtml::link if you don't you would have to do some more manipulation on the slug before you can render the link as you want it
0

#3 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 27 March 2012 - 12:15 PM

thats not what i said. the problem is that i can't build my url according to the information stored in the database. i stored the province name, municipality name and city name. those three together i used to build my sluge (SEO friendly name), also save in the database

So what goes wrong when i create an url:
$link = explode('-', $model->sluge);
$this->createUrl('city/view', array('id' => $model->id_city, 'province' => $link[0], 'municipality' => $link[1], 'city' => $link[2])


because the province and city i mentioned in the first post contains a dash (-)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users