public function actionSearch()
    {
    //	$this->layout = '//layouts/zazadun';
      if(Yii::app()->request->isPostRequest  && Yii::app()->request->getPost('q') && Yii::app()->request->getPost('pereparam')){
        $this->redirect(Yii::app()->request->addUrlParam('catalog/article/search', array('q'=>Yii::app()->request->getPost('q'))));
      }
      $model = new Article;
        $count_items = 0;
        if (($term = Yii::app()->getRequest()->getQuery('q')) !== null) {
            $this->pageTitle = CHtml::encode($term);
            $query = $term;

            $s = MHelper::String()->toLower(trim($term));
            $resultsPr = null;
            if(!empty($s)){
            $s = addcslashes($s, '%_'); // escape LIKE's special characters

             $criteria = new CDbCriteria;
            $criteria->scopes='fullactive';


            $criteria->condition ='(( (LOWER(t.title) LIKE :s) or (LOWER(t.description) LIKE :s) ))';
            $criteria->params = array(':s'=>"%$s%");
            $dataProvider = new CActiveDataProvider('Article', array(
                'criteria' => $criteria,
                'sort'       => array(
                    'defaultOrder' => 't.created_date DESC',
                ),
                'pagination' => array(
                    'pageSize' => 25,
                    'pageVar'=>'page'
                ),
            ));
            
          //  VarDumper::dump($dataProvider); die(); // Ctrl + X  Delete line
          }
          $count_items = 0;
          if ($dataProvider && $dataProvider->totalItemCount) { 
            $count_items = $dataProvider->totalItemCount;
          } 

          if(!empty($term) && !isset($_GET['page'])){
            $searchquery = new Searchqueries;
            $searchquery->query = $term;
            $searchquery->quantity = $count_items;
            $searchquery->ip_address = MHelper::Ip()->getIp();
            $searchquery->save();

          }
          $dtitle = $query.' ';
          $this->render('search', compact('term', 'query','dataProvider','count_items','model','dtitle'));
        } else {
          $term = $query = '';
          $dtitle = $query;
          $dataProvider = null;
          $this->render('search', compact('term', 'query','dataProvider','count_items','model','dtitle'));
        }
        
    }
    public function actionSearch()
    {
      if(Yii::app()->request->isPostRequest  && Yii::app()->request->getPost('q') && Yii::app()->request->getPost('pereparam')){
        $this->redirect(Yii::app()->request->addUrlParam('catalog/catalog/search', array('q'=>Yii::app()->request->getPost('q'))));
      }
       $this->layout = '//layouts/zazadun';
        $count_items = 0;
        if (($term = Yii::app()->getRequest()->getQuery('q')) !== null) {
            $this->pageTitle = CHtml::encode($term).' в '.$this->city->mestpad;
            $query = $term;

            $s = MHelper::String()->toLower(trim($term));
            $resultsPr = null;
            if(!empty($s)){
            $s = addcslashes($s, '%_'); // escape LIKE's special characters

            $criteria = new CDbCriteria;
            $criteria->scopes='active';
            $criteria->with = array(
              'categorization',
              'categories'=>array(
                 'together'=>true
                ),
              'city'=>array('together'=>true)
              );
           // $criteria->together = true;
         /*   $criteria->compare('t.city_id',$this->city_id);
            $criteria->compare('LOWER(t.title)',$s,true);
            $criteria->compare('LOWER(t.description)',$s,true,'OR');
            $criteria->compare('LOWER(t.synonim)',$s,true,'OR');
            $criteria->compare('LOWER(categories.title)', $s, true, 'OR');
            $criteria->compare('LOWER(categories.keywords)', $s, true, 'OR');
          */

            $criteria->condition ='(t.city_id = '.$this->city->id.' and ( (LOWER(t.title) LIKE :s) or (LOWER(t.synonim) LIKE :s) or (LOWER(t.description) LIKE :s) or (LOWER(categories.title) LIKE :s) or (LOWER(categories.keywords) LIKE :s)))';
            $criteria->params = array(':s'=>"%$s%");
            $resultsPr = new CActiveDataProvider('Orgs', array(
                'criteria' => $criteria,
                'sort'       => array(
                    'defaultOrder' => 't.title',
                ),
                'pagination' => array(
                    'pageSize' => 20,
                    'pageVar'=>'page'
                ),
            ));
            
          //  VarDumper::dump($resultsPr); die(); // Ctrl + X  Delete line
          }
          
          if ($resultsPr && $resultsPr->totalItemCount) { 
            $count_items = $resultsPr->totalItemCount;
          } 
          if(!empty($term) && !isset($_GET['page'])){
            $searchquery = new Searchqueries;
            $searchquery->query = $term;
            $searchquery->city_id = $this->city->id;
            $searchquery->quantity = $count_items;
            $searchquery->ip_address = MHelper::Ip()->getIp();
            $searchquery->save();

          }
         // $this->render('search', compact('term', 'query','resultsPr','count_items'));
          $dtitle = $term . ' '. $this->city->rodpad;
          $this->render('view',array(
          				'provider'=>$resultsPr,
                        'dtitle'=>$dtitle,
                        'itemView'=>'_organizations_view',
                        'count_items'=>$count_items
                        ));
        } else {
          $term = $query = '';
          $resultsPr = null;
          $dtitle = 'Поиск';
          $this->render('view',array(
          				'provider'=>$resultsPr,
                        'dtitle'=>$dtitle,
                        'itemView'=>'_organizations_view',
                        'count_items'=>$count_items
                        ));
        }
        
    }