Hello
I’m trying to use DetailView from Kartik, but using the delete icon/button doesn’t work.
Here is what I’m trying:
Controller
class TestController extends Controller
{
public function actionView($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('view', ['model' => $model]);
}
}
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
}
View
use kartik\detail\DetailView;
use yii\helpers\Url;
echo DetailView::widget([
'model' => $model,
'condensed'=>false,
'hover'=>true,
'mode'=>Yii::$app->request->get('edit')=='t' ? DetailView::MODE_EDIT : DetailView::MODE_VIEW,
'panel'=>[
'heading'=>$this->title,
'type'=>DetailView::TYPE_INFO,
],
'attributes' => [
'id',
'name',
],
'deleteOptions'=>[
'url'=>['delete', 'id' => $model->id],
'data'=>[
'confirm'=>Yii::t('app', 'Are you sure you want to delete this item?'),
'method'=>'post',
],
],
'enableEditMode'=>true,
])
Using firefox inspector I’ve noticed that when I click the delete button, it produces a POST request to view, not to the delete action (actionDelete) specified in the url param in deleteOptions.
I’m using Yii Version 2.0.4 and the instructions from Krajee Webtips (cannot insert link because the forum marks the post as spam ) but doesn’t work.
Any clues?