Wallace85
(Wallace)
August 30, 2011, 9:26pm
1
Hi,
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:
if(Yii::app()->request->isPostRequest)
How can I solve this problem?
drylko
(Pawel Drylo)
August 30, 2011, 11:21pm
2
Hi,
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
Wallace85
(Wallace)
August 31, 2011, 10:10am
3
drylko:
Hi,
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
Hi,
thx for your answer, but it not solves my problem. This code snippet creates the following link:
localhost/index.php?r="controllername"/index#
instead of
localhost/index.php?r="controllername"/delete&id=8
I dont know why
drylko
(Pawel Drylo)
August 31, 2011, 12:48pm
4
Wallace85:
This code snippet creates the following link:
localhost/index.php?r="controllername"/index#
instead of
localhost/index.php?r="controllername"/delete&id=8
Hi,
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:
localhost/index.php?r=site/index#
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
lubosdz
(Lubosdz)
August 31, 2011, 1:05pm
5
What database are you using?
Wallace85
(Wallace)
August 31, 2011, 1:23pm
6
drylko:
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
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
drylko
(Pawel Drylo)
August 31, 2011, 1:32pm
7
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.
Wallace85
(Wallace)
September 1, 2011, 11:24am
8
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.
jacmoe
(Jacob Moena)
September 1, 2011, 12:12pm
9
Use a linkbutton instead of just a link.
drylko
(Pawel Drylo)
September 1, 2011, 9:39pm
11
Could you, please, paste here your CGridView initialization?
Wallace85
(Wallace)
September 1, 2011, 11:49pm
12
yes, sure. it’s all standard generated code
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'termin-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'datum',
'club.name',
array(
'class'=>'CButtonColumn',
),
)
)); ?>
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?
jacmoe
(Jacob Moena)
September 2, 2011, 12:04am
13
Try and delete the contents of your assets directory.
drylko
(Pawel Drylo)
September 2, 2011, 7:45am
14
Well, then maybe there is some javascript error? Firebug doesn’t say anything?
And don’t forget to delete your assets like jacmoe said
Wallace85
(Wallace)
September 18, 2011, 1:05am
15
I had to update my jquery version! After doing this, it works!
Thx to all!