Reputation: 10335
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 ?
Upvotes: 7
Views: 7584
Reputation: 8988
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
Upvotes: 19
Reputation: 2757
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'];
...
Upvotes: 1