[MY BAD] Error in activeCheckBoxList method in CHhtml helper when using....

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);


	}


What is $news? It should be a model object.

$news is a model, please see below class declarasion.



<?php





class News extends CActiveRecord


{





  const STATUS_DRAFT=0;


  const STATUS_PUBLISHED=1;


  const STATUS_CANCELLED=2;


  const STATUS_ARCHIVED=3;  


  


  public $selectedCategories;


  public $allowedCategories;


  


	/**


	 * Returns the static model of the specified AR class.


	 * @return CActiveRecord the static model class


	 */


	public static function model($className=__CLASS__)


	{


		return parent::model($className);


	}





	/**


	 * @return string the associated database table name


	 */


	public function tableName()


	{


		return 'news';


	}





	/**


	 * @return array validation rules for model attributes.


	 */


	public function rules()


	{


		return array(


			array('title','length','max'=>100),


			array('author_desc','length','max'=>20),


			array('title, author_desc, date, time', 'required'),


			array('total_comments', 'numerical', 'integerOnly'=>true),


		);


	}





	/**


	 * @return array relational rules.


	 */


  public function relations()


  {


    return array(


      'author'=>array(self::BELONGS_TO, 'User', 'author_id'),


      'comments'=>array(self::HAS_MANY, 'NewsComment', 'news_id'),


      'category'=>array(self::HAS_MANY, 'NewsCategory', 'news_id'),


      'txt'=>array(self::HAS_ONE, 'NewsTxt', 'news_id'),


    );


  }


}


If $news is a model object, why would the error occur?

Hi. Sorry, my bad. I've, somehow, deleted from call of render method, a code, which passed into $news a model instance. Your question:

Quote

If $news is a model object, why would the error occur?

helps me to finds this out.