Yii2 Setting unknown property: yii\filters\auth\HttpBearerAuth::formats

urfusion

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

  1. 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). *
  2. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\BaseYii.php at line 525 – yii\base\Object::__set('formats', ['application/json' => 'json'])
  3. 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']])
  4. yii\base\Object::__construct(['only' => ['index', 'view', 'create', 'update', ...], 'formats' => ['application/json' => 'json']])
  5. 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']]])
  6. 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']])
  7. 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']])
  8. 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']])
  9. 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']])
  10. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Component.php at line 533 – yii\base\Component::ensureBehaviors()
  11. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Controller.php at line 272 – yii\base\Component::trigger('beforeAction', yii\base\ActionEvent)
  12. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\web\Controller.php at line 164 – yii\base\Controller::beforeAction(yii\rest\UpdateAction)
  13. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Controller.php at line 154 – yii\web\Controller::beforeAction(yii\rest\UpdateAction)
  14. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Module.php at line 523 – yii\base\Controller::runAction('update', ['id' => '1'])
  15. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\web\Application.php at line 102 – yii\base\Module::runAction('products/update', ['id' => '1'])
  16. in D:\xampp\htdocs\connect\vendor\yiisoft\yii2\base\Application.php at line 380 – yii\web\Application::handleRequest(yii\web\Request)
  17. 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

enter image description here

What could be the issue?

topher

The error is clear: the HttpBearerAuth class has no property formats so the following line shouldn't be under the HttpBearerAuth config:

'formats' => ['application/json' => Response::FORMAT_JSON,],

This is a property of \yii\filters\ContentNegotiator. See the docs on Content Negotiation for more details

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Eerror in social login in Yii2: Setting unknown property: yii\web\Application::authClientCollection

Yii2 migrate Setting unknown property: yii\caching\FileCache::backuprestore

Yii2 Login from DB (Setting unknown property: app\models\User::password_hash)

Getting unknown property Exception in yii2

Setting unknown property: yii\web\UrlRule::GET

Setting unknown property: yii\grid\GridView::export

Setting unknown property: yii\validators\NumberValidator::0

Yii2 - Getting unknown property: yii\console\Application::user

Unknown Property and programatically adding textfields in Yii2 form

Setting unknown property: yii\console\ErrorHandler::errorAction on linux server

Yii2 Invalid Call: Setting read-only property

Yii2 Setting read-only property

Kartik's yii2-grid: Setting unknown property: kartik\grid\GridView::panel

Yii2 - Getting unknown property: yii\console\Request::userAgent and Class db does not exist

Using property of parent class gives "unknown property" error in php (yii2)

Yii Framework Unknown Property Exception

yii2 beginWidget -> unknown method

Unknown Method - ActiveField::radioButtonList() in Yii2

Yii2: Setting layout for a specific controller

Setting a dynamic timezone in yii2

Setting Routes for RestApi in Yii2

Getting unknown property: yii\web\User::admin

Unknown Property – yii\base\UnknownPropertyException ::discription:html

Unknown Class – yii\base\UnknownClassException Yii2

Calling unknown method: yii\web\Application::createUrl() in yii2

How to customize Navbar property in Yii2

Yii2 Visibility Property on HTML

Add filter property to Yii2 yii\grid\ActionColumn class

YII2 unknown `with` and `joinWith` on joining two tables

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive