Yii2 PHP Framework get value Radiolist

Asked

Viewed 144 times

1

Good would like to know how to get the selected value in the Radiolist of Yii2 Framework:

<div class="row">
        <div class="col-sm-2">
            <?= $form->field($model, 'RADIO_LIST')->radioList($values, array('class' => 'test-checks'));  ?>
        </div>  
</div>  

1 answer

0

One of the options passed in the $values array will be selected by the user, and it will be possible to manipulate this value in the Controller of this view, for example:


create.php

<div class="row">
        <div class="col-sm-2">
            <?= $form->field($model, 'RADIO_LIST')->radioList($values, array('class' => 'test-checks'));  ?>
        </div>  
</div> 

<button class="btn-primary btn" type="submit">Salvar</button>

<?php ActiveForm::end() ?>

Then in Controller you will take from the request the data passed in the form:

Defaultcontroller.php

public function ActionCreate()
{
    $model = new Usuario();
    $model->load(Yii::$app->request->post); // insere o atributo (popula) no $model;

    $model->save();

    return $this->render('view', compact('model'));
}

view php.

<?= $model->RADIO_LIST ?> // exibe na tela o seu atributo com o valor passado no *create.php*

SUMMARY

On the screen form create.php was created the form field of type radio list, with an array of options for the user to select (variable $values), when clicking Ubmit, this selected value would be linked to the field, and sent to the controller where all processing would be done (validations, persistence, etc.), at the end of the controller is called the screen view php., where finally the value is accessed and displayed on the screen.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.