我正在使用yii2框架建立一个API,我需要告诉yii某些行动作为公共行动。除了控制器的行为功能,我添加了,但它不起作用
public function behaviors() {
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::className(),
'except' => ['NotifyOrder'],
];
return $behaviors;
}
public function actionNotifyOrder() {
echo 1;
}
当我致电/notify-order urol
时,我总是会遇到错误<response><name>Unauthorized</name><message>Your request was made with invalid credentials.</message><code>0</code><status>401</status><type>yiiwebUnauthorizedHttpException</type></response>
根据文档,您需要告诉它操作IDS (URL中使用的dash-expared格式)
你应该有
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::className(),
'except' => ['notify-order', 'another-action', 'and-so-on'],
];