Browse Source

商品表单提交时增加validate()方法判断

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
a480c5ca1d
  1. 4
      vendor/antgoods/goods/src/controllers/GoodsController.php
  2. 26
      vendor/antgoods/goods/src/views/goods/create.php
  3. 41
      vendor/antgoods/goods/src/views/goods/picture.php

4
vendor/antgoods/goods/src/controllers/GoodsController.php

@ -82,7 +82,7 @@ class GoodsController extends Controller
{ {
$model = new Goods(); $model = new Goods();
if ($model->load(Yii::$app->request->post())) {
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
//商品封面图和商品详情图上传保存处理 //商品封面图和商品详情图上传保存处理
$cover_image_id_str = $model->coverImageId; $cover_image_id_str = $model->coverImageId;
@ -121,7 +121,7 @@ class GoodsController extends Controller
$cover_image_old_id_arr = $model->image; $cover_image_old_id_arr = $model->image;
$detail_image_old_id_arr = $model->detailImageId; $detail_image_old_id_arr = $model->detailImageId;
if ($model->load(Yii::$app->request->post())) {
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
//商品封面图和商品详情图上传保存处理 //商品封面图和商品详情图上传保存处理
$cover_image_id_str = $model->coverImageId; $cover_image_id_str = $model->coverImageId;

26
vendor/antgoods/goods/src/views/goods/create.php

@ -13,29 +13,13 @@ $this->params['breadcrumbs'][] = $this->title;
Yii::$app->params['bsVersion'] = '4.x'; Yii::$app->params['bsVersion'] = '4.x';
?> ?>
<div class="goods-create"> <div class="goods-create">
<div class="goods-form">
<?php
$form = ActiveForm::begin();
echo TabsX::widget([
'bordered' => true,
'position' => TabsX::POS_ABOVE,
'encodeLabels' => false,
]);
<?=
$this->render('_form', [
'model' => $model,
])
?> ?>
<div class="form-group">
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
<?= Html::a('返回', ['index'], ['class' => 'btn btn-info']) ?>
</div> </div>
<?php ActiveForm::end(); ?>
<?php
// $this->render('_form', [
// 'model' => $model,
// ])
?>
</div> </div>

41
vendor/antgoods/goods/src/views/goods/picture.php

@ -0,0 +1,41 @@
<?php
use yii\helpers\Html;
use yii\bootstrap4\ActiveForm;
use antgoods\goods\models\ars\Category;
use antgoods\goods\models\ars\Brand;
use antgoods\goods\models\ars\ShopCategory;
use antgoods\goods\models\ars\Supplier;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $model antgoods\goods\models\ars\Goods */
/* @var $form yii\widgets\ActiveForm */
?>
<?= $form->field($model, 'coverImageId')->hiddenInput()->label('') ?>
<?= $form->field($model, 'coverImagePath')->widget(\iron\widgets\Upload::className(), [
'url' => 'upload',
'deleteUrl' => 'img-id-del',
'dragdropWidth'=> 800,
'afterSave' => 'save-file',
'maxCount' => 1,
'fillInAttribute' => 'coverImageId',
'model' => $model,
'previewConfig' => [
'url' => Url::to(['image-file', 'fileidstr' => $model->coverImageId]),
],
])->label('商品封面图') ?>
<?= $form->field($model, 'detailImageId')->hiddenInput()->label('') ?>
<?= $form->field($model, 'detailImagePath')->widget(\iron\widgets\Upload::className(), [
'url' => 'upload',
'deleteUrl' => 'img-id-del',
'dragdropWidth'=> 800,
'afterSave' => 'save-file',
'maxCount' => 5,
'fillInAttribute' => 'detailImageId',
'model' => $model,
'previewConfig' => [
'url' => Url::to(['image-file', 'fileidstr' => $model->detailImageId]),
],
])->label('商品详情图') ?>
Loading…
Cancel
Save