Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Error when params is a js function instead of an array and CSRF enabled #96

Closed
Darkheir opened this issue Feb 19, 2014 · 0 comments
Closed

Comments

@Darkheir
Copy link

When I set the params option as a js function and not an array I have the following error:

Illegal string offset 'YII_CSRF_TOKEN'

It comes from the following code in Editable.php line 435

if (Yii::app()->request->enableCsrfValidation) {
    $csrfTokenName = Yii::app()->request->csrfTokenName;
    $csrfToken = Yii::app()->request->csrfToken;
    if(!isset($this->params[$csrfTokenName])) {
        $this->params['YII_CSRF_TOKEN'] = $csrfToken;
    }
}

Since params is not an array the CSRF token can't be set. to solve it I check if this params is an array and I set the CSRF token in my javascript function.

if(!isset($this->params[$csrfTokenName]) && is_array($this->params)) {
    $this->params['YII_CSRF_TOKEN'] = $csrfToken;
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants