1
votes

While developing Yii2 Rest api came to this situation where I want to introduce a custom action with text parameter. Following is url manager

[
                    'class' => 'yii\rest\UrlRule', 
                    'controller' => 'v1/group',
                    'pluralize'=>false,
                    'extraPatterns' => [
                                            'GET groups' => 'groups', 
                                            'GET user/{id}' => 'user',
                                            'GET group/{id}' => 'group',
                                            'GET security' => 'security',
                                            'GET distribution' => 'distributionList'
  ]

when passing integer to id http://localhost/restfull/api/web/v1/group/user/123 like this it works fine, when passing a text parameter like 'abc123' if trows #404, any idea to fix this?

class xxxController extends ActiveController
{
    public $modelClass = 'api\modules\v1\models\xxxx';   


public function actionUser($id){
//action body
}

}
1

1 Answers

0
votes

Change the urlManager rule like below

'urlManager'=>array(
    ....
    'rules'=>array(
        'controller/test/<parameter:\w+>' => 'controller/test',
        ...
    ),
),