How To Write Url Manager Rules In This Case

hi,

in my application i have URL like this…

www.example.com/xyz/45678

now i want to modify it by

www.example.com/abc/food-new-canada(category-new or old-location)…

i know how to modify xyz with by url manager but i have doubt in 45678 to food-new-canada…

can anyone suggest me how to achieve it? is it possible?

Thanks in advance.

I think you can do that through the beforeAction in controller.php file

put all id and regarding values in an array then replace with id’s and forward the user request

can you give me some example code?

Can you give some example actions and arrays so that I can understand and re write your code

as i said in my question…

now my url is looking like

www.example.com/food/12345

but i want to change 13245 with new-spicy-canada(new/old-test-location)

www.example.com/food/new-spicy-canada

So as you said

food is the controller name? or action?

If it is action then 12345 always equals to new-spicy-canada ? I mean each id will be having its regarding strings?

food is controller name and 13245 is foodId… so instead of foodId i want to display new/old,test,location (these all are the fields of my table Food).

so in short instead of FoodId i want to display other attributes related to FoodId

Your action might be index? ok then you can use your query string as follows

?id=234&loc=canada&taste=spicy

i think you didn’t get what exactly i want…

now when i open food item for view from the list i am getting url www.example.com/food/12345. here food is controller name and 12345 is FoodId.

so what i want to it when i click on any food item from the list i want to make URL like this www.example.com/food/new-sweet-india

hi kalpit

add a url rule under your config/main.php




'<controller:\w+>/<name>'=>'<controller>/view',




//Controllers

you will have access to a $_POST['name'] in your controller 

...

$name = preg_replace('/-/', ' ', $_POST['name']);

$post=Post::model()->find('LOWER(name)=:name', array(':name'=>$name));

....


in your Model


...

    public $viewUrl;


   public function afterFind() 

   {

       $this->viewUrl = Yii::app()->request->baseUrl.'/conrollerName/'.strtolower(preg_replace('/\s+/', '-', $this->name));

       return parent::afterFind();

   }

...


//Views


finally replace urls with $model->viewUrl in your links