Difference between #1 and #2 of
default csrf security and ajax post in one controller

Revision #2 has been created by robregonm on Jan 20, 2014, 2:46:56 PM with the memo:

Small syntax updates and style fixes.
« previous (#1) next (#3) »

Changes

Title unchanged

default csrf security and ajax post in one controller

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

CSRF, security, php, ajax request, post

Content changed

Hello Yii friends I am going to write an article. ThatMany times we write asame code on every ajax call, but writing a single code in one controller is sufficient in ajax post with csrf security which is very easy. At first go to components and open the controller.php Simply add the following code:-
 
 
```php 
// this function will be initialize in every controller call which will call initAjaxCsrfToken function
 
 
public function init() { parent::init(); $this->initAjaxCsrfToken(); }     // this function will work to post csrf token.
 
protected function initAjaxCsrfToken() {

Yii::app()->clientScript->registerScript('AjaxCsrfToken', ' $.ajaxSetup({
[...]
cache:false
});', CClientScript::POS_HEAD);
}
 
```
Enjoy coding
0 3
8 followers
Viewed: 27 291 times
Version: 1.1
Category: Tutorials
Written by: jasonban
Last updated by: CeBe
Created on: Jan 20, 2014
Last updated: 10 years ago
Update Article

Revisions

View all history