Delete not working


I use the Gii Crud Generator to create the controller and view files. The problem is that the delete action doesn’t work. First of all the confirmation dialog doesn’t appear.

<?php  echo CHtml::link("Delete", array('Delete','id'=>'8'), array('confirm' => 'Are you sure?')); ?>

When I try to delete a record in the GridView I get the following error:

Invalid request. Please do not repeat this request again.

The error occurs here:


How can I solve this problem?


yes, this error is showing up because you are using GET method to delete a record.

You should use it like this:

<?php  echo CHtml::link("Delete", '#', array('confirm' => 'Are you sure?', 'submit'=>array('Delete','id'=>'8'))); ?>

with ‘submit’ param used in htmlOptions array you are creating a link that will be submitted via POST


thx for your answer, but it not solves my problem. This code snippet creates the following link:


instead of


I dont know why :(


assuming your current route is site/index the link

<?php  echo CHtml::link("Delete", '#', array('confirm' => 'Are you sure?', 'submit'=>array('Delete','id'=>'8'))); ?>

should look like:


and it’s ok.

If you check this element with firebug you will see that it has an id and when you check your html source you will also notice that there is a jQuery method call with that id - that jQuery method will look something like this

jQuery('body').undelegate('#yt0','click').delegate('#yt0','click',function(){if(confirm('Are you sure?')) {jQuery.yii.submitForm(this,'/index.php?r=site/Delete&id=8',{});return false;} else return false;}); 

where "yt0" is an id of your link

What database are you using?

yes, the link has the id "yt0" but apparently the jquery method is missing. There were only two scripts included:

<script type="text/javascript" src="/assets/2174755a/jquery.js"></script>

<script type="text/javascript" src="/assets/2174755a/jquery.yii.js"></script>

Do I have to iMnclude a specific script?

Btw. I use MySql as database

Ok, but when you click that generated link it does not remove that item/shows confirmation dialog? You are still seeing that bad request message?

Btw, you should see the generated script at the bottom part of your document’s body tag.

You do not have to include anything specific if you are using default CClientScript configuration.

Yes, when I create the link with this command:

<?php  echo CHtml::link("Delete", '#', array('confirm' => 'Are you sure?', 'submit'=>array('delete','id'=>'8'))); ?>

The dialog is only shown when I try to delete in the gridview, but then I get the bad request message.

Yes, thats right, but it doesn’t work. It’s very strange.

Use a linkbutton instead of just a link. :)

still not working :(

Could you, please, paste here your CGridView initialization?

yes, sure. it’s all standard generated code

<?php $this->widget('zii.widgets.grid.CGridView', array(












)); ?>

its very strange because there are other functions which are not working anymore. For example I use the CJuiDatePicker for date input. it works fine but now no calandar is shown. ( i dont touch the appropriate file! I swear! :) )

Does yii cache websites anywhere?

Try and delete the contents of your assets directory. :)

Well, then maybe there is some javascript error? Firebug doesn’t say anything?

And don’t forget to delete your assets like jacmoe said :)

I had to update my jquery version! After doing this, it works!

Thx to all!