我在每個YII2
創建API和每個請求運作良好,但在PUT
要求我得到以下錯誤Yii2設置未知屬性:警予過濾器權威性 HttpBearerAuth ::格式
財產來源不明 - 警予\基地\ UnknownPropertyException
設置未知屬性:警予\過濾器\權威性\ HttpBearerAuth ::格式
這是我的堆棧跟蹤
在d:\ XAMPP \ htdocs中\連接\廠商\ yiisoft \ yii2 \基\ Object.php在線161 152153154155156157158159160161162163164165166167168169170
*/ 公共函數__set($名稱,$值) { $ setter ='set'。 $名稱;如果(method_exists($ this,$ setter)){ $ this - > $ setter($ value); ('this'($ this,'get'。$ name)){ throw new InvalidCallException('Setting the read-only property:'。get_class($ this)。'::'。$ name); ('設置未知屬性:'。get_class($ this)。'::'。$ name);}}返回新的UnknownPropertyException。 } }/**
- 檢查一個屬性被設置,即定義和不爲空。 *
- 不要直接調用此方法,因爲它是一種PHP魔術方法,當執行
isset($object->property)
時,將隱式調用- 。 *
- 在d:\ XAMPP \ htdocs中\連接\廠商\ yiisoft \ yii2 \ BaseYii.php在線路525 - YII \基\對象:: __集( '格式',[ '應用/ JSON' => 'json'])
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ base \ Object.php在第105行 - yii \ BaseYii :: configure(yii \ filters \ auth \ HttpBearerAuth , ['only'=> ['index','view','create','update',...],'formats'=> ['application/json'=>'json']])
- yii \ base \ Object :: __ construct(['only'=> ['index','view','create','update',...],'formats'=> ['application/json '=>'json']])
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ di \ Container.php在第381行 - ReflectionClass :: newInstanceArgs([['only'=> ['index', 'view','創建','更新',...],'格式'=> ['application/json'=> 'json']]])
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ di \ Container.php 156行 - yii \ di \ Container :: build('yii \ filters \ auth \ HttpBearerAuth', [],['only'=> ['index','view','創建','更新',...],'格式' => ['application/json'=''json']])
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2在第344行的BaseYii.php - yii \ di \ Container :: get('yii \ filters \ auth \ HttpBearerAuth',[], ['only'=> ['index' ,'查看','創建','更新',...],'formats'=> ['application/json'=''json']])
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ base \ Component.php at 667 - yii \ BaseYii :: createObject(['class'=> 'yii \ filters \ auth \ HttpBearerAuth','only'=> ['index','view', 'create','update',... ],'formats'=> ['application/json'=> 'json']])
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ base \ Component.php at line 651 - yii \ base \ Component :: attachBehaviorInternal(0,['class' =>'yii \ filters \ auth \ HttpBearerAuth','only'=> ['index','view','create','update', ...],'formats'=> ['application/json'=> 'json']])
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ base \ Component.php在533行 - yii \ base \ Component :: ensureBehaviors()
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ base \ Controller.php在第272行 - yii \ base \ Component :: trigger('beforeAction', yii \ base \ ActionEvent)
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft yii \ base \ Controller :: beforeAction(yii \ rest \ UpdateAction)中的\ yii2 \ web \ Controller.php
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ base \ Controller。 php在線154 - yii \ web \ Controller :: beforeAction(yii \ rest \ UpdateAction)
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ base \ Module.php在第523行 - yii \ base \ Controller :: runAction('update',['id'=>'1'])
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ web \ Application .php at line 102 - yii \ base \ Module :: runAction('products/update',['id'=> '1'])
- in D:\ xampp \ htdocs \ connect \ vendor \ yiisoft \ yii2 \ base \ Application.php at line 380 - yii \ web \ Application :: handleRequest(yii \ web \ Request)
- in D:\ xampp \ htdocs \ connect \ index.php at line 12 - yii \ base \ Application :: run()6789101112 require(DIR。 '/vendor/autoload.php');要求(DIR。 '/vendor/yiisoft/yii2/Yii.php'); $ config = require(DIR。 '/config/web.php'); (new yii \ web \ Application($ config)) - > run(); $ _GET = [ 'id'=>'1',]; Yii框架2017年2月23日,9時31分51秒
阿帕奇/ 2.4.23(Win32的)的OpenSSL/1.0.2h PHP/28年5月6日Yii框架/ 2.0.11.2
行爲在控制器
public function behaviors() {
return [
[
'class' => HttpBearerAuth::className(),
'only' => ['index', 'view', 'create', 'update', 'search'],
'formats' => ['application/json' => Response::FORMAT_JSON,],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'index' => ['get'],
'view' => ['get'],
'create' => ['post'],
'update' => ['PUT'],
'delete' => ['delete'],
'deleteall' => ['post'],
'search' => ['get']
],
]
];
}
我與postman
測試它在每個API傳遞Authorization
。
這是我的頭
可能是什麼問題?
我在標頭中傳遞'Content-Type:application/json'和'Accept:application/json'。我需要添加其他東西嗎? Doc正在說'$ curl -i -H「接受:application/json; q = 1.0,*/*; q = 0.1」「http:// localhost/users」' – urfusion
我不認爲你需要添加任何東西其他。嘗試一下,看看 – topher
還是一樣的錯誤。 – urfusion