views:

1065

answers:

2

I just learning yii framework and read this tutorial about yii how to setup url

but I have no idea, suppose i have 10 controllers, should I define one by one controllers in the config file ? is there a better way to setup url friendly like www.yoursite.com/yourController/yourAction/yourID for all controller ?

I think codeigniter did that automatically ... how about yii ?

+1  A: 

There are automatical URL generation in Yii too. For example just write in your template such URL without manual route:

<?php echo CHtml::link('topic title',array('topic/view','id'=>$topic->id,'var'=>'123')); ?>

And rendered URL will be as follow:

/topic/view/id/1/var/123

Then in our action actionView() method we use these parameters:

...
$id=$_GET['id'];
$var=$_GET['var'];
...
Sergei
+7  A: 

In /protected/config/main.php add..

  'urlManager'=>array(
  'urlFormat'=>'path',
   'showScriptName' => false,  
        ),
    ),

In your web root an .htaccess..

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
Chris
I wish I could give +10 votes for this answer, as finding it would have saved me an hour of searching and struggling to get it to work properly.
Milan Babuškov