Friday, November 15, 2013

yii multiple table with multiple column search

       $criteria = new CDbCriteria;
       $criteria->compare('fullname',$_GET['User']['keyword'],true,'OR'); // $_GET['User']['keyword'] search field name
       $criteria->compare('email',$_GET['User']['keyword'],true,'OR');
       $criteria->compare('phone',$_GET['User']['keyword'],true,'OR');
       $criteria->compare('presentaddress',$_GET['User']['keyword'],true,'OR');
       $criteria->compare('profession',$_GET['User']['keyword'],true,'OR');
       $criteria->with = array('homedistrict0','bloodgroup0','upozila0'); // Relation name
       $criteria->compare('homedistrict0.name',$_GET['User']['keyword'],true,'OR');
       $criteria->compare('upozila0.name',$_GET['User']['keyword'],true,'OR');
       $criteria->compare('bloodgroup0.name',$_GET['User']['keyword'],true,'OR');
       $criteria->together = true;

No comments:

Post a Comment