简体   繁体   中英

Yii framework: Controller url & parameters

In my application I have "PController" with default action "actionIndex" , so in Yii the path becomes p OR p/index . Now in order to get certain users info I use the following path p/index?u=test where test is the username and u part of the path is basically a GET parameter (p/index?u=test).

Is there any way to do the same thing without index?u= part of the path, ie I want my path to look like example.com/p/test ?

In your application config find section for components and add options for urlManager

array(
    ......
    'components' => array(
        ......
        'urlManager'=>array(
            'showScriptName' => false,
            'urlFormat' => 'path',
            'rules' => array(
                '/p/<u:\w+>'=>'p/index'
            ),
        ),
    ),
);

http://www.yiiframework.com/doc/guide/1.1/en/topics.url

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM