ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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
تم إضافة السؤال من قبل Khadijah Shtayat , Technical Lead , Opensooq
تاريخ النشر: 2013/11/27
Sohaib AlZyoud
من قبل 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);

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟