开发者

Using forms and checkboxlists in Yii

开发者 https://www.devze.com 2023-02-09 03:58 出处:网络
Am trying to wrap my head around using checkboxlists in the yii framework. Example: With the dropdownlist I can

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开发者_StackOverflow format it?


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消