<response>
<id>5</id>
<username>test12</username>
<auth_key/>
<password_hash/>
<password_reset_token/>
<email/>
<status>10</status>
<created_at>0</created_at>
<updated_at>1442992195</updated_at>
</response>
1.在配置文件中
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
// '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
['class' => 'yii\rest\UrlRule', 'controller' =>['auth','user'],'extraPatterns' => [
'GET {id}/testfun' => 'testfun', // 'xxxxx' refers to 'actionXxxxx' 'GET,HEAD {id}' => 'view',
],],
]
],
其中
'extraPatterns' => [
'GET {id}/testfun' => 'testfun', // 'xxxxx' refers to 'actionXxxxx' 'GET,HEAD {id}' => 'view',
]
参考 UrlRules中的写法
public $patterns = [
'PUT,PATCH {id}' => 'update',
'DELETE {id}' => 'delete',
'GET,HEAD {id}' => 'view',
'POST' => 'create',
'GET,HEAD' => 'index',
'{id}' => 'options',
'' => 'options',
];
2.在AuthController中
public function actionTestfun($id)
{
$model = User::findOne(5);
return $model;//var_dump('dsf');
// prepare and return a data provider for the "index" action
}
3.访问http://www.niuhun.com/basic/web/auths/4/testfun
显示
<response>
<id>
5
</id>
<username>
test12
</username>
<auth_key/>
<password_hash/>
<password_reset_token/>
<email/>
<status>
10
</status>
<created_at>
0
</created_at>
<updated_at>
1442992195
</updated_at>
</response>