I've found that since version 1.0.3 there is posibility to pass into CHtml::listData() method result of queryAll
Quote
a list of model objects. Starting from version 1.0.3, this parameter can also be an array of associative arrays (e.g. results of CDbCommand::queryAll).
I've decided to use this feature together with CHtml::activeCheckBoxList method.
part of view where activeCheckBoxList method is used
<?php echo CHtml::activeCheckBoxList(
$news, //news model
'selectedCategories', //array of selected values e.g. [0]=>1, [2]=>7, etc
CHtml::listData(
Category::model()->findAll(),
'id',
'category'
)
);
?>
As a result of this code I see following error message
Quote
Fatal error: Call to a member function hasErrors() on a non-object in D:\eclipse\workspace\pdt\yii.svn\web\helpers\CHtml.php on line 1097
As you can see in the code, $model->hasErrors method can't be called, because $model has as a result an array.
public static function activeCheckBoxList($model,$attribute,$data,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
$selection=$model->$attribute;
if($model->hasErrors($attribute))
self::addErrorCss($htmlOptions);
$name=$htmlOptions['name'];
unset($htmlOptions['name']);
return self::hiddenField($name,'',array('id'=>self::ID_PREFIX.$htmlOptions['id']))
. self::checkBoxList($name,$selection,$data,$htmlOptions);
}