第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 EditableColumn 在 Gridview 中更新一個原始單元格中的兩個單元格

使用 EditableColumn 在 Gridview 中更新一個原始單元格中的兩個單元格

PHP
縹緲止盈 2021-09-18 21:19:28
我的 Yii2 應用程序中有一個可編輯的 GridView,并使用了 kartik EditableColumn。當只有一個可編輯列時,一切正常,但是當我嘗試再添加一個可編輯列時,它會保存Price列的編輯值并將expire_days列的值設置為零。相反的方式相同(如果更新expire_days它保存值但將價格值設置為零)。風景:'columns' => [    [        'class'=>'kartik\grid\EditableColumn',        'attribute' => 'price',        'editableOptions'=>[            'header'=>' ',                                     'inputType'=>\kartik\editable\Editable::INPUT_SPIN,            'options'=>['pluginOptions'=>['min'=>0, 'max'=>5000000]]        ],        'value' => function ($model) {            return $model->price;         },        'filter' => Category::getPrices(),        'format' => 'raw'    ],    [        'class'=>'kartik\grid\EditableColumn',        'attribute' => 'expire_days',        'editableOptions'=>[            'header'=>' ',            'inputType'=>\kartik\editable\Editable::INPUT_SPIN,            'options'=>['pluginOptions'=>['min'=>0, 'max'=>100]]         ],        'value' => function ($model) {            return $model->expire_days;         },        'filter' => Category::getExpDays(),        'format' => 'raw'    ],                                         ]控制器:if (Yii::$app->request->post('hasEditable')) {    $model = new Category();    $id = Yii::$app->request->post('editableKey');    $model = Category::findOne($id);    $out = Json::encode(['output'=>'', 'message'=>'']);    $post = [];    $posted = current($_POST['Category']);    $post['Category'] = $posted;    if ($model->load($post)) {        $model->price = $post['Category']['price'];        $model->expire_days = $post['Category']['expire_days'];        $model->save();        $output = '';        $out = Json::encode(['output'=>$output,'message'=>'']);    }    echo $out;    return;}
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

您應該分別處理兩種情況:


if ($model->load($post)) {

    if ($post['Category'] && $post['Category']['price']) {

        $model->price = $post['Category']['price'];

    }


    if ($post['Category'] && $post['Category']['expire_days']) {

        $model->expire_days = $post['Category']['expire_days'];

    }

    $model->save();

    $output = '';

    $out = Json::encode(['output'=>$output,'message'=>'']);

}

如果您收到價格 - 您只更新價格。如果您收到 expire_days - 更新 expire_days。


查看完整回答
反對 回復 2021-09-18
  • 1 回答
  • 0 關注
  • 241 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號