yii - yii2: how to add if for checked or unchecked checkbox in _form.php -


i want add if or else checkbox in _formcreate.php

this checkbox:

   <div class="col-lg-6 height3">          <p class="col-lg-8">سرگرمی</p> <?= $form->field($model, 'c2')->input('checkbox', ['id' => '', 'value'=> '2', 'class' => 'col-lg-4 chb'])->label('') ?>      </div>             <div class="col-lg-6 height3">                 <p class="col-lg-8">خدماتی</p> <?= $form->field($model, 'c3')->input('checkbox', ['id' => '', 'value' => '3', 'class' => 'col-lg-4 chb'])->label('') ?>              </div> 

i have variable in form $checkbox data:

array(3) { [0]=> array(1) { ["project_type_id"]=> string(1) "2" } [1]=> array(1) { ["project_type_id"]=> string(1) "3" } [2]=> array(1) { ["project_type_id"]=> string(1) "5" } }  

how add if <?= $form->field... , check array , checked checkbox!

if right, can write logic checkbox (model's attribute) in beginning of view. example, if model's name 'yii', checkbox should automatically checked, in code write way:

<?php  /* @var $this yii\web\view */ /* @var $model somemodel */  if($model->name == 'yii') $model->c2 = true;  ?> 

then in form:

<div class="col-lg-6 height3">   <p class="col-lg-8">سرگرمی</p>     <?= $form->field($model, 'c2')->checkbox()->label('') ?> </div> <div class="col-lg-6 height3">   <p class="col-lg-8">خدماتی</p>     <?= $form->field($model, 'c3')->checkbox()->label('') ?> </div>