Yii2 更新Kartik Detailview中的数据';行不通

Yii2 更新Kartik Detailview中的数据';行不通,yii2,updates,edit,detailview,kartik-v,Yii2,Updates,Edit,Detailview,Kartik V,我已经用Kartik细节视图展示了细节。此小部件通过单击右上角的铅笔图标按钮(如下所示),具有编辑内联功能 然后该表将如下所示进行编辑: 我已经编辑了数据,然后单击Floopy磁盘图标按钮保存 而且什么也没发生,我的数据还是一样,我的更新没有成功 这是我在view.php中的代码 <?= DetailView::widget([ 'model' => $model, 'condensed' => true, 'hover' => true,

我已经用Kartik细节视图展示了细节。此小部件通过单击右上角的铅笔图标按钮(如下所示),具有编辑内联功能

然后该表将如下所示进行编辑: 我已经编辑了数据,然后单击Floopy磁盘图标按钮保存

而且什么也没发生,我的数据还是一样,我的更新没有成功

这是我在view.php中的代码

<?=
DetailView::widget([
    'model' => $model,
    'condensed' => true,
    'hover' => true,
    'mode' => DetailView::MODE_VIEW,
    'panel' => [
        'heading' => 'Data Details',
        'type' => DetailView::TYPE_INFO,
    ],
    'attributes' => [
        'product',
        'productId',
        'distDate',
        'created_at',
        'created_by',
        [
            'attribute' => 'is_exported',
            'value' => $model->isExported->name,
        ],
    ],
    'buttons1' => '{update}',
])
?>
我使用纯动作,我没有更改控制器中的代码

这是我的模型
Line
$model=$this->findModel($id)

您正在控制器上使用
$this
,因此它试图从数据库(不存在)中查找控制器的数据。此外,controller中没有此类方法
findModel()
,应该在具有
ActiveRecord
扩展名的模型上使用。正确的用法是:

$model = VatoutFakturOut::findOne($id);
但是,这个小部件似乎没有传递任何
$id
(因此,
actionUpdate($id)
中的参数
$id
是无用的)。如何取得身份证?从
Yii::$app->request->post()['vatouthakturout']['productId']
。但如果已定义,则应检查它,否则您将收到警告:

$post = Yii::$app->request->post();

if (empty($post['VatoutFakturOut']['productId'])) {
    throw new NotFoundHttpException('Not found.');
}
第三件事是你给了用户编辑ID的能力(即使它没有被覆盖)。。。这是你不应该做的。我将稍微更改查看文件的代码:

'attributes' => [
    'product',
    [
        'attribute' => 'productId', 
        'options' => ['readonly' => true],
    ],
    'distDate',
    'created_at',
    'created_by',
    [
        'attribute' => 'is_exported',
        'value' => $model->isExported->name,
    ],
],
假设
productId
是主键。这将不允许用户编辑此字段,但它仍将被发送到控制器

最终结果是:

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

    if (empty($post['VatoutFakturOut']['id'])) {
        throw new NotFoundHttpException('VatoutFakturOut not found.');
    }

    $model = VatoutFakturOut::findOne($post['VatoutFakturOut']['id']);

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

那么你处理请求的控制器呢?你应该通知我这些更改。我没有注意到。:)很抱歉,我忘了注意你:(,我的错,我没有错。你能提供你的模型吗?嗨@EdvinTenovimas,模型已经添加。请查看。谢谢
'attributes' => [
    'product',
    [
        'attribute' => 'productId', 
        'options' => ['readonly' => true],
    ],
    'distDate',
    'created_at',
    'created_by',
    [
        'attribute' => 'is_exported',
        'value' => $model->isExported->name,
    ],
],
public function actionUpdate()
{
    $post = Yii::$app->request->post();

    if (empty($post['VatoutFakturOut']['id'])) {
        throw new NotFoundHttpException('VatoutFakturOut not found.');
    }

    $model = VatoutFakturOut::findOne($post['VatoutFakturOut']['id']);

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