V
V
Victor Umansky2017-04-17 02:26:03
Yii
Victor Umansky, 2017-04-17 02:26:03

Saving prices for a certain category?

Hi all.
It is not possible to save the price for a certain category ..... the user selects his specialty, saves it, then transfers him to another tab for setting the price, or if the user decides to change the price (PRICE SHOULD BE DISPLAYED IN INPUT), then he changes the value ... like everything, I CAN'T UNDERSTAND HOW TO IMPLEMENT CORRECTLY!
f60847180d.png
DB:
c0f48661ae.png
controller:

public function actionProfile()
    {
....
        $price = ($price = ProfileHasCategory::findAll(['user_id' => $user_id])) ? $price : new ProfileHasCategory();

        return $this->render('profile', [
             .......................
            'price' => $price,
        ]);
....
}

view:
<?php foreach ($price as $k) : ?>
                <?php $form = ActiveForm::begin() ?>
                <tr>
                    <td>1</td>
                    <td><?= $k->category_id ?></td>
                    <td>
                        <div class="col-md-2">
                            <?= $form->field($k, 'price')->textInput()->label('') ?>
                        </div>
                    </td>
                    <td><?= Html::submitButton('<span class="glyphicon glyphicon-ok"></span>', ['class' => 'btn btn-success']) ?></td>
                </tr>
                <?php $form = ActiveForm::end() ?>
            <?php endforeach; ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-04-17
@slo_nik

Good morning.
Why translate to another page in order to indicate the price? All this can be done on one and in one form.
Show the model, validation rules for the price.
What do you want to achieve with this?

$price = ($price = ProfileHasCategory::findAll(['user_id' => $user_id])) ? $price : new ProfileHasCategory();

V
Viktor Umansky, 2017-04-17
@Uman

you need to make a hidden input for categories

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question