1:修改Url Manager,例如下边这个例子是在customer这个控制器中添加一个新的action叫token
1 'urlManager'=>array( 2 'enablePrettyUrl'=>true, 3 'showScriptName'=>false, 4 'rules' => [ 5 ['class' => 'yii estUrlRule', 'controller' => 'version'], 6 ['class' => 'yii estUrlRule', 'controller' => 'customer', 'pluralize' => false,//指定依然是现有的控制器controller 7 'extraPatterns' => [ 8 'GET token/<username:w+>/<password:w+>' => 'token', //注意这里的token首字母是小写,并且指定ActionToken这个控制器有两个参数'username'和'password' 9 ], 10 ], 11 ] 12 ),
2:修改控制器的代码:
class CustomerController extends ActiveController { public $modelClass = 'appmodelsCustomer'; public function actionToken($username, $password) { return Yii::$app->request->getPathInfo(); } }