I am creating apis in YII2
each and every request is working well but in PUT
request I am getting below error
Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: yii\filters\auth\HttpBearerAuth::formats
This is my stack trace
in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Object.php at line 161 152153154155156157158159160161162163164165166167168169170
*/ public function __set($name, $value) { $setter = 'set' . $name; if (method_exists($this, $setter)) { $this->$setter($value); } elseif (method_exists($this, 'get' . $name)) { throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name); } else { throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name); } }/**
- Checks if a property is set, i.e. defined and not null. *
- Do not call this method directly as it is a PHP magic method that
- will be implicitly called when executing
isset($object->property)
. *- in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\BaseYii.php at line 525 – yii\base\Object::__set('formats', ['application/json' => 'json'])
- in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Object.php at line 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 at line 381 – ReflectionClass::newInstanceArgs([['only' => ['index', 'view', 'create', 'update', ...], 'formats' => ['application/json' => 'json']]])
- in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\di\Container.php at line 156 – yii\di\Container::build('yii\filters\auth\HttpBearerAuth', [], ['only' => ['index', 'view', 'create', 'update', ...], 'formats' => ['application/json' => 'json']])
- in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\BaseYii.php at line 344 – yii\di\Container::get('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 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 at line 533 – yii\base\Component::ensureBehaviors()
- in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Controller.php at line 272 – yii\base\Component::trigger('beforeAction', yii\base\ActionEvent)
- in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\web\Controller.php at line 164 – yii\base\Controller::beforeAction(yii\rest\UpdateAction)
- in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Controller.php at line 154 – yii\web\Controller::beforeAction(yii\rest\UpdateAction)
- in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Module.php at line 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'); require(DIR . '/vendor/yiisoft/yii2/Yii.php'); $config = require(DIR . '/config/web.php'); (new yii\web\Application($config))->run(); $_GET = [ 'id' => '1', ]; Yii Framework 2017-02-23, 09:31:51
Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28 Yii Framework/2.0.11.2
Behaviors in controller is
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']
],
]
];
}
I am testing it with postman
and passing Authorization
in each api.
This is my header
What could be the issue?