How to get record count

Hi guys, Im new to Yii and Im having trouble getting the count of records using CDbCriteria. Here are some of my codes.




$criteria = new CDbCriteria;

$criteria->select = 'title, COUNT(title) as title_count';

$criteria->order = 'title_count DESC';

$criteria->distinct = TRUE;

$criteria->group = 'title';


$provider = new CActiveDataProvider('Titles', array('criteria' => $criteria));



My view file




$this->widget('zii.widgets.CListView', array(

    'dataProvider'=> $provider,

    'itemView'=>'_fragmentview',

    'summaryText' => '',

));



My problem is accessing title_count on "_fragmentview.php" file. I can successfully call title using


echo CHtml::encode($data->title);

, but when on title_count, it throws an error "Property "Titles.title_count" is not defined.". Any idea on how to solve this?

Thanks.

Obviously, you have to define this property in your model class before trying to access it:




public $title_count;



It worked. Thanks a lot!