Since two days I try to find my error. I found lot’s of questions and answers in the internet. Now at the end, I need your help …
I want to have a delete-button in a view. For security-reasons I only use "Post"-requests. I tried lots of suggestions from this forum and ended up with the following … without success:
Controller:
public function filters() {
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
); // added
public function actionDelete($id) {
$this->loadModel($id)->delete();
if (!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
View:
<?php
// [...] deleted html and text to keep the example short [...]
echo CHtml::ajaxLink('X', Yii::app()->createUrl('comment/delete'), array(
'type' => 'POST',
'data' => 'js:{"data":' . $comment->id . '}',
'success' => 'js:function(string){ document.getElementById("' . $comment->id . '").remove(); }'),
array(
'class' => 'btn btn-danger small-btn',
'confirm' => 'Are you sure?' //Confirmation
));
?>
I get the question "Are you sure" but after answering … no deletion happens.
I just did one other test:
commenting the following out:
// 'postOnly + delete'
Another test: deleting with CGridView works.
This seems to be important … but no idea what to do. You?