Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii : how to count records in a model?

Tags:

php

yii

I have following code to fetch data from a model.

$notifyModel = Notification::model()->findByAttributes(array(
                  'user_id'=> Yii::app()->user->uid
               ));

Now I want to count the number of rows fetched. Neither $notifyModel->count() work nor count($notifyModel). It is very simple but googling did not help.

like image 286
Gunah Gaar Avatar asked Dec 04 '12 23:12

Gunah Gaar


1 Answers

$notifyModels = Notification::model()->findAllByAttributes(array(
            'user_id'=> Yii::app()->user->uid
        ));

$count = count($notifyModels);

Or

$count = Notification::model()->countByAttributes(array(
            'user_id'=> Yii::app()->user->uid
        ));
like image 187
Willem Renzema Avatar answered Sep 18 '22 20:09

Willem Renzema