【发布时间】:2017-12-26 02:09:10
【问题描述】:
我已经使用 Kartik Detail View 进行了详细展示。此小部件具有 编辑 内联功能,可通过单击右上角的铅笔图标按钮,如下所示
然后表格将可以像这样编辑: 我已经编辑了数据,然后单击“Floopy Disk Icon”按钮保存。
什么也没发生,我的数据还是一样,我的更新没有成功。
这是我在 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}',
])
?>
为什么小部件没有保存编辑的数据?我的代码有什么问题?
更新:
这是我控制器中的操作:
public function actionUpdate($id) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->productId]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
我用的是纯动作,Controller里面的代码我没有改。
这是我的模型
<?php
namespace app\modules\vatout\models;
use Yii;
class VatoutFakturOut extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'vatout_faktur_out';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'parent_id', 'product'], 'required'],
[['user_id', 'parent_id', 'is_exported'], 'integer'],
[['distDate', 'updated_at', 'created_at'], 'safe'],
[['updated_by', 'created_by'], 'string', 'max' => 16],
[['product'], 'string', 'max' => 128],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'producrID' => 'Product ID',
'user_id' => 'User ID',
'parent_id' => 'Parent ID',
'distDate' => 'Dist Date',
'Product' => 'Product',
'is_exported' => 'Is Exported',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIsExported()
{
return $this->hasOne(VatoutStatus::className(), ['id' => 'is_exported']);
}
}
【问题讨论】:
-
那么处理请求的控制器呢?
-
您应该通知我有关更改的信息。我没有注意到这一点。 :)
-
对不起,我忘了注意到你:(,我的错
-
我没有错。你能提供你的模型吗?
-
嗨@EdvinTenovimas,模型已添加。请检查一下。谢谢
标签: yii2 updates edit detailview kartik-v