Kartik Detailview 中的更新数据不起作用

Update data in Kartik Detailview is not working

我使用 Kartik 细节视图显示了细节。通过单击右上角的铅笔图标按钮,此小部件具有编辑内联功能。

但是 table 不是 editable :

什么也没发生,我的数据还是一样,我的更新没有成功。 有可能解决我的问题?谢谢。

我已经阅读了官方指南,它看起来是一样的: https://demos.krajee.com/detail-view

这是我的查看代码:

<?php echo DetailView::widget([
        'model' => $modelAnagrafiche,
        'responsive' => true,
        'mode' => 'edit',
        'enableEditMode' => true,
        'buttons1' => '{update}',
        'panel' => [
            'type' => 'primary',
            'heading' => 'Contratto' . ' : ' . $modelAnagrafiche >cognome_ragione_sociale . ' ' . $modelAnagrafiche->nome
        ],
        'attributes' => [
            [
                'group'=>true,
                'label'=>'Sezione Anagrafica',
                'rowOptions'=>['class'=>'table-primary']
            ],
            [
                'columns' => [
                    [
                        'attribute' => 'cognome_ragione_sociale',
                        'displayOnly' => true,
                        'valueColOptions' => ['style' => 'width:30%']
                    ],
                    [
                        'attribute' => 'nome',
                        'format' => 'raw',
                        'valueColOptions' => ['style' => 'width:30%'],
                        'displayOnly' => true,
                        'type' => DetailView::INPUT_TEXT,
                    ],
                ],
            ],
            [
                'columns' => [
                    [
                        'attribute' => 'codice_fiscale',
                        'displayOnly' => true,
                        'valueColOptions' => ['style' => 'width:30%']
                    ],
                    [
                        'attribute' => 'partita_iva',
                        'format' => 'raw',
                        'valueColOptions' => ['style' => 'width:30%'],
                        'displayOnly' => true
                    ],
                ],
            ],
            [
                'columns' => [
                    [
                        'attribute' => 'tipo_documento',
                        'displayOnly' => true,
                        'valueColOptions' => ['style' => 'width:30%'],
                        'format' => 'raw',
                        'value' => $modelAnagrafiche->tipoDocumento,
                    ],
                    [
                        'attribute' => 'numero_documento',
                        'format' => 'raw',
                        'valueColOptions' => ['style' => 'width:30%'],
                        'displayOnly' => true
                    ],
                ],
            ],
            [
                'columns' => [
                    [
                        'attribute' => 'data_nascita',
                        'displayOnly' => true,
                        'format' => 'date',
                        'type' => DetailView::INPUT_DATE,
                        'widgetOptions' => [
                            'pluginOptions' => ['format' => 'yyyy-mm-dd']
                        ],
                    ],
                    [
                        'attribute' => 'id_provincia_nascita',
                        'displayOnly' => true,
                        'valueColOptions' => ['style' => 'width:30%'],
                        'format' => 'raw',
                        'value' => $modelAnagrafiche->provinciaNascitaNome,
                        'label' => 'Provincia Nascita'
                    ],
                ],
            ],
            [
                'columns' => [
                    [
                        'attribute' => 'id_comune_nascita',
                        'displayOnly' => true,
                        'format' => 'raw',
                        'value' => $modelAnagrafiche->comuneNascitaNome,
                        'label' => 'Comune Nascita'
                    ],
                ],
            ],
        ],
    ]);
?>

这是我控制器中的动作:

public function actionUpdateAnagrafica()
{
    $post = Yii::$app->request->post();

    if (empty($post['Anagrafiche']['id'])) {
        throw new NotFoundHttpException('Non esiste nessuna anagrafica.');
    }

    $modelAnagrafiche = Anagrafiche::findOne($post['Anagrafiche']['id']);

    if ($modelAnagrafiche->load($post) && $modelAnagrafiche->save()) {
        return $this->redirect(['view', 'id' => $modelAnagrafiche->id]);
    } else {
        return $this->render('update-anagrafica', [
            'modelAnagrafiche' => $modelAnagrafiche,
        ]);
    }
}

您必须删除所有 displayOnly 属性。

根据官方指南:

displayOnly: boolean|Closure, if the input is to be set to as display only in edit mode. If set to true, no editable form input will be displayed, instead this will display the formatted attribute value.