2017-09-06 3 views
0

J'utilise Yii2 comme framework dans le développement PHP. Dans mon ticket.php, le "time_end" aura automatiquement l'heure de l'ordinateur quand une donnée spécifique dans ticket.php va Pour être mis à jour mon problème est quand il est mis à jour, il ne s'affiche pas sur la vue. Il dit (non-set)La valeur mise à jour dans le formulaire n'apparaît pas à l'affichage

Mon TicketController.php

public function actionCreate() 
{ 
    $model = new Ticket(); 

    if ($model->load(Yii::$app->request->post()) && $model->save()) { 
     return $this->redirect(['view', 'id' => $model->id]); 
    } else { 
     $model->time_start = date('d-m-y h:i:s'); 
     return $this->render('create', [ 
      'model' => $model, 
     ]); 
    } 
} 

/** 
* Updates an existing Ticket model. 
* If update is successful, the browser will be redirected to the 'view' page. 
* @param integer $id 
* @return mixed 
*/ 
public function actionUpdate($id) 
{ 
    $model = $this->findModel($id); 

    if ($model->load(Yii::$app->request->post()) && $model->save()) { 
     return $this->redirect(['view', 'id' => $model->id]); 
    } else { 
      $model->time_end = date('d-m-y h:i:s');    
      return $this->render('update', [ 
      'model' => $model, 
     ]); 

    } 
} 

Mon _form.php

<?= $form->field($model, 'time_end')->widget(DateTimePicker::className(), 
            [ 
             'value' => date('d-m-y h:i:s'), 
             'disabled' => true 
            ] 


); ?> 

Le view.php

<?php 

use yii\helpers\Html; 
use yii\widgets\DetailView; 

/* @var $this yii\web\View */ 
/* @var $model app\models\Ticket */ 

$this->title = $model->id; 
$this->params['breadcrumbs'][] = ['label' => 'Tickets', 'url' => ['index']]; 
$this->params['breadcrumbs'][] = $this->title; 
?> 
<div class="ticket-view"> 

<h1><?= Html::encode($this->title) ?></h1> 

<p> 
    <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> 
    <?= Html::a('Delete', ['delete', 'id' => $model->id], [ 
     'class' => 'btn btn-danger', 
     'data' => [ 
      'confirm' => 'Are you sure you want to delete this item?', 
      'method' => 'post', 
     ], 
    ]) ?> 
</p> 
+0

je l'var_dump et il montre l'heure du système, j'ai ajouté le view.php – noobkoder

+0

je l'ai déjà trouvé un moyen pour fixer le « set pas » mais quand je mets à jour le formulaire il met à jour à la fois time_start et time_end – noobkoder

Répondre

0

Ajouter champ TIME_END à la sécurité en les règles.

par exemple

public function rules() 
{ 
    return array(
     array('username, password, salt, email', 'required'), 
     array('username, password, salt, email', 'length', 'max'=>128), 
     array('profile', 'safe'), 
    ); 
}