Count(Criteria) In Yii

hi i’m using yii restful api

normally use this Criteria to select offerdetail model data related with place_id

                        [color="#9ACD32"]//http://localhost/coupon3.0/index.php/api/OfferDetail?place=1[/color]


			if (isset($_GET['place']))


			{ 


				$Criteria = new CDbCriteria();


				$Criteria->condition = sprintf("place_id = %s", $_GET['place']);


				$models = OfferDetail::model()->findAll($Criteria);


		


			}

Now i want to get num of offerdetail row related with place_id

Query [color="#FF0000"]SELECT count( * )FROM offer_detailWHERE place_id = ‘3’ ;[/color]

how select this using criteria on web service help 

[u]HINT :-[/u]

i try like this

 http://localhost/coupon3.0/index.php/api/OfferDetail?count=1


  if (isset($_GET['count'])){	          


  $Criteria = new CDbCriteria();


  $Criteria->condition = sprintf("place_id = %s", $_GET['count']);			           $count=OfferDetail::model()->count($Criteria);				

$models = OfferDetail::model()->findAll($Criteria);

			}

But Not Working

Hi,




$place_id = Yii::app()->request->getParam('place');

if($place_id) {

 //build criteria

 $criteria = new CDbCriteria();

 $criteria->condition = 'place_id = :place_id';

 $criteria->params = array(':place_id' => $place_id);


 //query items

 $models = OfferDetail::model()->findAll($criteria);

 //count items

 $count = OfferDetail::model()->count($criteria);

}




Some words about the code:

First, try to avoid using the globals, Yii have it’s own parameter handler.

Second, sprintf validates the variable type, but not gives as much protection as the Yii parameter binding over PDO.

Third, but it lacks in my example also, I better prefer building setter/getter methods in the model, not in the controller/view. But this is just my opinion, not a requirement.