tags:

views:

673

answers:

1

In my application I have "ApiController" with "actionUsers", so in Yii the path becomes api/users. Now in order to get certain users info I use the following path api/users/id/10 where 10 is the userID and id part of the path is basically a GET parameter (api/users?id=10).

Is there any way to do the same thing without id part of the path, i.e. I want my path to look like api/users/10?

Thank you!

+1  A: 

You're going to need to put in rule patterns in the urlManager component: http://www.yiiframework.com/doc/guide/topics.url

Your config should look something like this:

array(
    ......
    'components'=>array(
        ......
        'urlManager'=>array(
            'urlFormat'=>'path',
            'rules'=>array(
                'api/users/<id>'=>'api/users',
            ),
        ),
    ),
);

You can then get the value by:

$id = Yii::app()->getRequest()->getQuery('id');
Shiki