TbHtml::activeCheckBoxList PHP Method

activeCheckBoxList() public static method

Generates a check box list for a model attribute.
public static activeCheckBoxList ( CModel $model, string $attribute, array $data, array $htmlOptions = [] ) : string
$model CModel the data model.
$attribute string the attribute.
$data array $data value-label pairs used to generate the check box list.
$htmlOptions array additional HTML attributes.
return string the generated list.
    public static function activeCheckBoxList($model, $attribute, $data, $htmlOptions = array())
    {
        parent::resolveNameID($model, $attribute, $htmlOptions);
        $selection = parent::resolveValue($model, $attribute);
        if ($model->hasErrors($attribute)) {
            parent::addErrorCss($htmlOptions);
        }
        $name = TbArray::popValue('name', $htmlOptions);
        $uncheckValue = TbArray::popValue('uncheckValue', $htmlOptions, '');
        $hiddenOptions = isset($htmlOptions['id']) ? array('id' => parent::ID_PREFIX . $htmlOptions['id']) : array('id' => false);
        $hidden = $uncheckValue !== null ? parent::hiddenField($name, $uncheckValue, $hiddenOptions) : '';
        return $hidden . self::checkBoxList($name, $selection, $data, $htmlOptions);
    }

Usage Example

 /**
  * Renders a checkbox list for a model attribute.
  * @param CModel $model the data model.
  * @param string $attribute the attribute.
  * @param array $data data for generating the list options (value=>display)
  * @param array $htmlOptions additional HTML attributes.
  * @return string the generated checkbox list.
  * @see TbHtml::activeCheckBoxList
  */
 public function checkBoxList($model, $attribute, $data, $htmlOptions = array())
 {
     return TbHtml::activeCheckBoxList($model, $attribute, $data, $htmlOptions);
 }
All Usage Examples Of TbHtml::activeCheckBoxList
TbHtml