Yii2: Call to a member function validateCsrfToken() on string

Created on 5 Jul 2020  路  12Comments  路  Source: yiisoft/yii2

i have a problem after ((Controller::$request and $response)) change
in beforeAction when we print (( $this->validateCsrfToken() )) it returns : 'request' not an object
it seems $this->validateCsrfToken() has not the same value as Yii::$app->getRequest()->validateCsrfToken()
and this problem stops my controllers
please resolve this

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.15
| PHP version | 7.2
| Operating system | centos

need more info

Most helpful comment

Do you have an init(); in your SiteController?

If so you need to call parent::init();

All 12 comments

Can you confirm which version you are on?
Latest Yii2 is 2.0.35 which is 20 releases ahead of the one you listed.

If you are on .15 can you update to .35 and test again.

Can you confirm which version you are on?
Latest Yii2 is 2.0.35 which is 20 releases ahead of the one you listed.

If you are on .15 can you update to .35 and test again.

updated to .35 but still the same error

Would you please provide full error message including file, line and stracktrace?

Would you please provide full error message including file, line and stracktrace?

Screenshot (364)

Do you have an init(); in your SiteController?

If so you need to call parent::init();

Do you have an init(); in your SiteController?

If so you need to call parent::init();

true, it seems solved
thanks

I have the same issue, but my SiteController doesn't have an init();
I'm running Yii2 version 2.0.36
Is there another way to solve this issue or do I need to add an init(); function and call parent::init(); in there?

Does your SiteController extend from another custom Controller class?

Yes. I have just found what my issue was. Thank you.

Do you have an init(); in your SiteController?

If so you need to call parent::init();

I upgraded from 2.015 to 2.0.35 and also had this problem

Thanks, that solves my problem

I upgraded from 2.015 to 2.0.35 and also had this problem
Also i tried to call the method init() and and it doesn't work either(
Can anyone help me?

Please use the Forum if you have any questions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dhiman252 picture dhiman252  路  44Comments

sepidemahmoodi picture sepidemahmoodi  路  104Comments

deecode picture deecode  路  50Comments

gpoehl picture gpoehl  路  47Comments

samdark picture samdark  路  52Comments