Difference between #8 and #9 of
Using search engine and user friendly URLs

Revision #9 has been created by Yang He on Jun 30, 2012, 7:20:28 AM with the memo:

Removed broken Chinese version link
« previous (#8)


Title unchanged

Using search engine and user friendly URLs

Category unchanged


Yii version unchanged

Tags unchanged


Content changed

We can save this base class in a file named `ActiveRecord.php` and put it under the directory `protected/components` so that when we extend this class to write new model classes, we do not need to explicitly include this class file, thanks to the Yii class autoloading feature.

With the above approach, we can achieve very flexible URL schemes while keeping our code clean. If some day we want to change the format of the detail page URL (e.g., besides title, we also want to add category information into the URL), we can immediately accomplish this by updating only the `getUrl()` method in the base class. If, a model has a very special format for its detail page URL, we can override the `getUrl()` method in this model class.

Finally, it may also be a good idea to implement in the model classes the methods that return other type of URLs. For example, we can implement the `getListUrl()` method in the base class similar to what we do for `getUrl()`. Then we can readily obtain the list page URL for `Post` model using the expression `Post::model()->listUrl`.

### Links
[Chinese version](http://projects.ourplanet.tk/node/97)
19 0
Viewed: 81 464 times
Version: 1.1
Category: Tutorials
Tags: SEO, URL
Written by: qiang
Last updated by: Yang He
Created on: Oct 23, 2009
Last updated: 5 years ago
Update Article


View all history