Yii Framework Forum: How to get record count - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to get record count Rate Topic: -----

#1 User is offline   sessy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 18-March 10

Posted 18 March 2010 - 03:04 AM

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

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 18 March 2010 - 03:28 AM

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

public $title_count;

0

#3 User is offline   sessy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 18-March 10

Posted 18 March 2010 - 04:07 AM

View Postandy_s, on 18 March 2010 - 03:28 AM, said:

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

public $title_count;



It worked. Thanks a lot!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users