Yii2 PHP Framework get value RadioList

1

I'd like to know how to get the value selected in the Yii2 Framework's RadioList:

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

1 answer

0

One of the options passed in the $ values array will be selected by the user, and you can 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 the Controller you will get the data passed in the form from the request:

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

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

    
29.03.2018 / 16:22