Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

How can I get the value for aggregate query in Yii if the aggregate value not an attribute on the activerecord class?

$criteria = new CDbCriteria(); $criteria->select = 'type , seen, count(1) As counts'; $criteria->condition = 'mb = :mb AND deleted = false AND archived = false'; $criteria->params = array(':mb'=>$mb); $criteria->group = 'type ,seen'; $counters = $this->findAll($criteria); the problem is How can I get the value for (counts ) if its not as attribute on class? I try to $counters[0]->counts but not worked

user-image
Question ajoutée par Khadijah Shtayat , Technical Lead , Opensooq
Date de publication: 2013/11/27
Sohaib AlZyoud
par Sohaib AlZyoud , Senior Software Engineer , Secured Services Systems (SSSIT)

You cant access the value unless its an attribute on the model (or) and attribute on the table,

 

quick solution :

on the model file add new attribute (member variable) and use it in the query

 

class xxModel {

public $countOfX;

}

 

$criteria = new CDbCriteria(); $criteria->select = 'type , seen, count(1) As countOfX'; $criteria->condition = 'mb = :mb AND deleted = false AND archived = false'; $criteria->params = array(':mb'=>$mb); $criteria->group = 'type ,seen'; $counters = $this->findAll($criteria);

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?