Yii:: SEO friendly url with hypen or dash


With Yii, to have a friendly url with dash like this http://www.pulaisprings.com/proposal/photo-gallery.html

You can add this code into your controller:

public function missingAction($action_id) {
         * Support dash separated action ids: convert whatever-action-id to actionWhateverActionId method name, check if it exists and if it does - run it.
        $action_id = explode('-', $action_id);
        $action_id = array_map('strtolower', $action_id);
        $action_id = array_map('ucfirst', $action_id);
        $action_id = implode('', $action_id);
        if (method_exists($this, 'action' . $action_id) || array_key_exists('action' . $action_id, $this->actions())) {
        else {
            throw new CHttpException(404);
then create your menu url something like this: <?php echo CHtml::normalizeUrl(array('photo-gallery')) ?>

<li><a id="photo" href="<?php echo CHtml::normalizeUrl(array('photo-gallery')) ?>" title="Photo Gallery">Photo Gallery</a></li>

*** this function i copy from Yii forum.. not sure who is the author.. please email me if you know who is the author.. will give credit to him/her.


2 thoughts on “Yii:: SEO friendly url with hypen or dash

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s