[ASK] Mohon dibantu, clean url dengan CBaseUrlRule

Mastah,

mohon dibantu, saya stuck dengan clean URL, masih ga bisa sesuai keinginan…

current url : http://localhost/font/view/slug/zurich-extended-bt

pengennya : http://localhost/zurich-extended-bt

class FontUrlRule yang dibuat :


<?php

class FontUrlRule extends CBaseUrlRule

{

    public $connectionID = 'db';

 

    public function createUrl($manager,$route,$params,$ampersand)

    {

        if($route==='font/view')

        {

            if (isset($params['slug']))

                return $params['slug'];

        }

        return false;  // this rule does not apply

    }

 

    public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)

    {

        if(preg_match('%^[a-z0-9\-]+$%', $pathInfo, $matches))

        {

            $slug=$matches[0];

            $command=Yii::app()->db->createCommand();

            $result=$command->select('slug')->from('font');

            $result->where('slug=:slug', array(':slug'=>$slug));

            $result = $result->queryRow();

            if(!empty($result)&&$result['slug']===$slug)

            {

                $_GET['slug']=$result['slug'];

                return 'font/view';

            }

        }

        return false;  // this rule does not apply

    }

}

?>

trus di config main , aktifkan :


'class' => 'application.components.FontUrlRule',

      'connectionID' => 'db',

Kira2,mana yg tidak bener ya mastah??? Trims ya sebelumnya…