Validation and Displaying Dialog Message

In my view.php I have a close ticket button. When I select that button it will automatically get the system time and the status will be change into ‘Done’, thanks to the help of a guy here I forgot his username.

What I want to try is that when I click the close button if the ticket has already been done, the time_end won’t be changed and it will display a popup message similar to the delete button.

What I have tried so far is this:

 public function actionClose($id)


        $model = $this->findModel($id);

   //     $model->status = ('Done');

   //     $model->time_end = date('y-m-d h-i-s');

   //     $model->save();

   //     return $this->redirect(['view', 'id' => $model->id]);

        if ($model->status == 'Done' && $model->time_end == date('y-m-d h-i-s')) {

            (['data' => ['prompt' => 'Ticket has already been closed!']]);

        } else {

            $model->status = ('Done');

            $model->time_end = date('y-m-d h-i-s');


            return $this->redirect(['view', 'id' => $model->id]);


My problem is that it does not display a message and it still gets the system time even though the ticket status is already ‘Done’. I think I’m also wrong here at this part

(['data' => ['prompt' => 'Ticket has already been closed!']]);

that’s why it does not display a message.

problem is your if condition, your second check will always be false

if ($model->status == 'Done' && $model->time_end == date('y-m-d h-i-s')) {

date(‘y-m-d h-i-s’) will return current time and your $model->time_end is date in the past which will never be equal perhaps you should stick with only status something like

if ($model->status == 'Done') {

// task done

} else {

// update task


Thank you for help, I also did that I deleted the $model->time_end and it worked without even knowing why but since you explained it to me I finally know now.

I’m currently reading the docu I’m still having a problem on how am I going to display a pop up message similar to the delete button.

I’ve already figure it out by using the flash message and also with the help of the bootstrap alert.

Here’s what I did

Yii::$app->session->setFlash('msg', '

                <div class="alert alert-success alert-dismissable">

                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>

                <strong>Validation error! </strong>The ticket has already been closed!</div>'


return $this->redirect(['view', 'id' => $model->id]);

Then in my view.php

<?= Yii::$app->session->getFlash('msg') ?>