dimanche 30 avril 2017

How to create true or false checkbox in Yii2?

I have a problem here. In my ActiveForm I need to create a simple checkbox (which has to be a boolean value (0 - if the item was unpaid and 1 - if it was paid).

I've created in my view file a checkbox like this:

<?= $form->field($model, 'sign')->checkboxList([
    '' => '',
]); ?>

I thought that if I will mark the checkbox it will automatically will change to 1 (because in the database the value was set was boolean), but now it's writing that it must be an integer. When I'm deleting my rule and submitting my form, that value in the database is NULL.

So could anyone tell me how to do a checkbox, which if I would mark it, the value in the database would be 1, otherwise - 0? Thank you for any help..




Aucun commentaire:

Enregistrer un commentaire