1

Am trying to wrap my head around using checkboxlists in the yii framework.

Example: With the dropdownlist I can

<?php echo $form->dropdownlist($model,'fathercattle',array(1=>Yours,2=>Mine,3=>Nobody)); ?>

How do I get a similar effect using the Yii checkboxlists option?The values will be stored and retrieved in a database field as an array?

Secondly how do I get to format it?

1 Answer 1

6

You use the checkboxlist in much the same way as the dropdownlist. Take a look at the activecheckboxlist reference. Also, if you want the data to come from the DB you can use the function CHtml::listData to transform an array of active records into a data array for the activecheckbox.

In regards to your second question, you can format the checkboxlist using the htmlOptions array. Two useful options are:

  • template: string, specifies how each checkbox is rendered. Defaults to "{input} {label}", where "{input}" will be replaced by the generated check box input tag while "{label}" be replaced by the corresponding check box label.
  • labelOptions: array, specifies the additional HTML attributes to be rendered for every label tag in the list. This option has been available since version 1.0.10.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.