This is nuts. I have searched and guessed. I am out of bullets.

Can anyone please show me how CheckBoxList works?



    <?= $form->field($model, 'notify[]')->checkboxList($model->getNotifyKeys(),  ...WHAT GOES HERE  ) ?>

Here is the list returned by getNotifyKeys:


return [

            self::APPROVAL             =>'Approvals',                               

            self::ENCODING_READY       =>'Video encoding ready',                    

            self::FRIEND_ACCEPT        =>'Friend request accepted',                 

            self::PM                   =>'Private message on site',                 

            self::NEWSLETTER           =>'Newsletter',                              

            self::FORUM_POST           =>'Forum post to subscribed thread',         

            self::RECEIPT              =>'Receipt for payment',                     

            self::VIDEO_COMMENT        =>'Comment on your video',                   

            self::EXPIRY_REMINDER      =>'Membership expiry reminder',              


What do I put in the arguments to CheckBoxList to have, say NEWSLETTER already checked?

A sample. An example. SHOW ME THE CODE !! ;)

Please and thank you.

Preset the value in the field.

see this thread.

ya I saw that thread (which is also found on SO). Didn’t work for me. Perhaps another reading in the morning would make sense.

Meantime I did this on my own using checkboxes and a loop.

Thank you for your time.

This little snippet works for me.

Preselecting ItemId’s 4,7 and 8

    <?php $form = ActiveForm::begin(); ?>


      $model = $searchModel;

      $items = app\models\Item::find()->all();

      $listData = ArrayHelper::map($items, 'ItemId', 'FromLocation');

      $model->FromLocation = [4,7,8];


    <?= $form->field($model, 'FromLocation')->checkboxlist($listData) ?>

    <?php ActiveForm::end(); ?>

In my case the listData and field use the same model.

I think it will work with $someModel->someSelectedItem(s).

Thank you both. I am finding Yii2 to be the most pleasant php framework I have used. Really appreciate the responses, they helped me over my blind spot.