1:修改Url Manager,例如下边这个例子是在customer这个控制器中添加一个新的action叫token
‘urlManager‘=>array( ‘enablePrettyUrl‘=>true, ‘showScriptName‘=>false, ‘rules‘ => [ [‘class‘ => ‘yii\rest\UrlRule‘, ‘controller‘ => ‘customer‘], [‘class‘ => ‘yii\rest\UrlRule‘, ‘controller‘ => ‘customer‘, ‘pluralize‘ => false,//指定依然是现有的控制器controller ‘extraPatterns‘ => [ ‘GET token‘ => ‘token‘, //注意这里的token首字母是小写 ], ], ] ),
2:修改控制器的代码:
public function actionToken()//注意这里的token首字母是大写 { return ‘abc‘; }
时间: 2024-12-17 12:22:20