H
H
hollanditkzn2017-03-28 11:57:45
Yii
hollanditkzn, 2017-03-28 11:57:45

How to change data on click on submit?

The situation is such that I need when a certain submit role clicks in the database, the value changes automatically. If an order has come to the department in more detail, it needs to be processed when the department has processed it and it is ready, when you click on the button, the status changes automatically and it is displayed in another department.
I tried doing this in the controller

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

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id_zakaz]);
        } else {
            return $this->render('view', [
            'model' => $this->findModel($id),
            'user_name' => $user_name,
            ]);
        }

And in the view itself, I wrote the following code
<?php $form = ActiveForm::begin(); ?>
        <?php if (Yii::$app->user->can('master')): ?>
        <?= $form->field($model, 'status')->hiddenInput(['value' => '7'])->label(false) ?>
        <?= Html::submitButton('Выполнено', ['class' => 'btn btn-primary']) ?>
        <?php endif ?>
<?php ActiveForm::end(); ?>

I hope you don't have to show all the code.
At the moment my status does not change

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-03-28
@hollanditkzn

1. Open the debug panel and see why, there is an answer there. We are not mediums. And you have all the answers in the debug panel at your fingertips. Maybe the request does not go there or the validation does not pass.
2. All your views can be replaced by:

<?= Html::a('Выполнить', ['check', 'id' => $model->id], [
            'class' => 'btn btn-primary',
            'data' => [
                'confirm' => 'Вы уверены, что хотите одобрить эту ерунду?',
                'method' => 'post',
            ],
        ]) ?>

Further, in the controller, you can leave something like this (it can be more beautiful, but I'm afraid I'll confuse):
public function actionCheck($id)
    {
        if($model = $this->findModel($id)){
           $model->status = 7;
           $model->save();
        }
        return $this->redirect(Yii::$app->request->referrer);
    }

A
Arman, 2017-03-28
@Arik

Maybe because rules() doesn't have a rule for status?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question