how to setup url friendly in yii framework automat

2019-01-31 04:29发布

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 ?

2条回答
老娘就宠你
2楼-- · 2019-01-31 05:27

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'];
...
查看更多
爷、活的狠高调
3楼-- · 2019-01-31 05:31

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
查看更多
登录 后发表回答