浏览代码

Corriger bug "id_etablissement" perdu lors de l'update

master
keun 8 年前
父节点
当前提交
b619dc7616
共有 7 个文件被更改,包括 14 次插入22 次删除
  1. +8
    -7
      backend/controllers/ProduitController.php
  2. +2
    -8
      backend/views/produit/_form.php
  3. +1
    -2
      common/models/PointVente.php
  4. +3
    -5
      common/models/Produit.php
  5. 二进制
      frontend/web/uploads/rameau-556562071cbe4-580f11e41a914.jpg
  6. 二进制
      frontend/web/uploads/rameau-556562071cbe4-580f1289a88bc.jpg
  7. 二进制
      frontend/web/uploads/rameau-556562071cbe4-580f162babdc1.jpg

+ 8
- 7
backend/controllers/ProduitController.php 查看文件

@@ -94,9 +94,10 @@ class ProduitController extends Controller
$model = new Produit();

if ($model->load(Yii::$app->request->post()) && $model->save()) {
self::uploadFile($model, 'illustration') ;
self::uploadFile($model, 'photo') ;
Upload::uploadFile($model, 'illustration') ;
Upload::uploadFile($model, 'photo') ;
$model->save() ;
// on ajoute un enregistrement ProductionProduit pour chaque production
$productions = Production::find()->where('date > '.date('Y-m-d'))->all() ;
foreach($productions as $prod) {
@@ -106,7 +107,7 @@ class ProduitController extends Controller
$production_produit->actif = 0 ;
$production_produit->save() ;
}
return $this->redirect(['index']);
} else {
return $this->render('create', [
@@ -126,9 +127,9 @@ class ProduitController extends Controller
$request = Yii::$app->request ;
$model = $this->findModel($id);
$illustration_filename_old = $model->illustration ;
$photo_filename_old = $model->photo ;
$illustration_filename_old = $model->illustration ;
$photo_filename_old = $model->photo ;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Upload::uploadFile($model, 'illustration', $illustration_filename_old) ;
Upload::uploadFile($model, 'photo', $photo_filename_old) ;

+ 2
- 8
backend/views/produit/_form.php 查看文件

@@ -23,14 +23,6 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'poids')->textInput() ?>
<?= $form->field($model, 'quantite_max')->textInput() ?>
<?= $form->field($model, 'illustration')->fileInput() ?>
<?php
if(strlen($model->illustration)) {
echo '<img src="../../frontend/web/uploads/'.$model->illustration.'" width="200px" /><br />' ;
echo '<input type="checkbox" name="delete_illustration" id="delete_illustration" /> <label for="delete_illustration">Supprimer l\'illustration</label><br /><br />' ;
}
?>
<?= $form->field($model, 'photo')->fileInput() ?>
<?php
if(strlen($model->photo)) {
@@ -48,6 +40,8 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'samedi')->checkbox() ?>
<?= $form->field($model, 'dimanche')->checkbox() ?>
<?= $form->field($model, 'id_etablissement')->hiddenInput()->label('') ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

+ 1
- 2
common/models/PointVente.php 查看文件

@@ -106,9 +106,8 @@ class PointVente extends \yii\db\ActiveRecord
public function save($runValidation = true, $attributeNames = NULL)
{
$this->id_etablissement = 0 ;
$this->id_etablissement = Yii::$app->user->identity->id_etablissement ;
$this->pain = 1 ;
return parent::save($runValidation, $attributeNames) ;
}
}

+ 3
- 5
common/models/Produit.php 查看文件

@@ -37,15 +37,13 @@ class Produit extends \yii\db\ActiveRecord
public function rules()
{
return [
[['nom'], 'required'],
[['actif','order','quantite_max'], 'integer'],
[['nom', 'id_etablissement'], 'required'],
[['actif','order','quantite_max', 'id_etablissement'], 'integer'],
[['lundi','mardi','mercredi','jeudi','vendredi','samedi','dimanche','epuise'], 'boolean'],
[['prix', 'poids'], 'number'],
[['illustration','photo'], 'file'],
[['nom', 'description', 'illustration', 'photo', 'saison','diminutif'], 'string', 'max' => 255],
[['recette'], 'string','max'=>1000],
['id_etablissement','integer'],
['id_etablissement','required'],
];
}

@@ -100,7 +98,7 @@ class Produit extends \yii\db\ActiveRecord
public function save($runValidation = true, $attributeNames = NULL)
{
$this->id_etablissement = 0 ;
$this->id_etablissement = Yii::$app->user->identity->id_etablissement ;
return parent::save($runValidation, $attributeNames) ;
}
}

二进制
frontend/web/uploads/rameau-556562071cbe4-580f11e41a914.jpg 查看文件

之前 之后
宽度: 602  |  高度: 400  |  大小: 24KB

二进制
frontend/web/uploads/rameau-556562071cbe4-580f1289a88bc.jpg 查看文件

之前 之后
宽度: 602  |  高度: 400  |  大小: 24KB

二进制
frontend/web/uploads/rameau-556562071cbe4-580f162babdc1.jpg 查看文件

之前 之后
宽度: 602  |  高度: 400  |  大小: 24KB

正在加载...
取消
保存