Yii Framework

Error 400: The CSRF token could not be verified

Written by Ian Carnaghan · 38 sec read >

Getting Error 400: The CSRF token could not be verified. when trying to delete an item using the default delete link.

$this->menu=array(
array(‘label’=>’Create Use’, ‘url’=>array(‘create’)),
array(‘label’=>’Update Use’, ‘url’=>array(‘update’, ‘id’=>$model->use_id)),
array(‘label’=>’Delete Use’, ‘url’=>’#’, ‘linkOptions’=>array(‘submit’=>array(‘delete’,’id’=>$model->use_id,’confirm’=>’Are you sure you want to delete this item?’)),
array(‘label’=>’Manage Uses’, ‘url’=>array(‘admin’)),
);

Answer:

This problem can be solved by adding ‘csrf’ => true to the linkOptions

$this->menu=array(
array(‘label’=>’Create Use’, ‘url’=>array(‘create’)),
array(‘label’=>’Update Use’, ‘url’=>array(‘update’, ‘id’=>$model->use_id)),
array(‘label’=>’Delete Use’, ‘url’=>’#’, ‘linkOptions’=>array(‘submit’=>array(‘delete’,’id’=>$model->use_id,’confirm’=>’Are you sure you want to delete this item?’),’csrf’=>true)),
array(‘label’=>’Manage Uses’, ‘url’=>array(‘admin’)),
);

Last Updated On March 22, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. In my spare time I teach undergraduate classes in web development. Profile

Leave a Reply

avatar
  Subscribe  
Notify of