Пример #1
0
 public function run()
 {
     $tags = preg_replace('/(\\s)+/', ',', trim(Yii::app()->request->getParam('tag')));
     $tag_ids = array();
     if ($tags) {
         $arr_tag = explode(',', $tags);
         foreach ($arr_tag as $tag) {
             $t = Tag::model()->find('tag_name = :tn', array(':tn' => $tag));
             $t && ($tag_ids[] = $t->id);
         }
     } else {
         $alltags = Tag::model()->findAll(array('order' => 'data_count'));
         foreach ((array) $alltags as $tv) {
             $tag_ids[] = $tv->id;
         }
     }
     if (!$tag_ids) {
         throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.'));
     }
     $datas = array();
     $td = new TagData();
     $criteria = new CDbCriteria();
     $criteria->addColumnCondition(array('status' => 'Y'));
     $criteria->addInCondition('tag_id', $tag_ids);
     $criteria->group = 'content_id, type';
     //分页
     $count = $td->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $tddata = $td->findAll($criteria);
     if ($tddata) {
         foreach ($tddata as $value) {
             $modelType = ModelType::model()->findByPk($value->type);
             $model = $modelType->model;
             $value['type'] = $modelType->type_key;
             $value['data'] = $model::model()->findByPk($value->content_id);
             if ($value['data']) {
                 $datas[] = $value;
             }
         }
     }
     //SEO
     $this->controller->_seoTitle = $tags ? $tags . ' - ' . $this->controller->_setting['site_name'] : '所有标签 - ' . $this->controller->_setting['site_name'];
     $navs[] = array('url' => Yii::app()->request->getUrl(), 'name' => $tags ? $tags : '所有标签');
     $this->controller->render('index', array('navs' => $navs, 'datas' => $datas, 'pagebar' => $pages, 'tags' => $tags));
 }
Пример #2
0
 public function run()
 {
     $tags = preg_replace('/(\\s)+/', ',', trim(Yii::app()->request->getParam('tag')));
     $tag_ids = array();
     if ($tags) {
         $arr_tag = explode(',', $tags);
         foreach ($arr_tag as $tag) {
             $t = Tag::model()->find('tag_name = :tn', array(':tn' => $tag));
             $t && ($tag_ids[] = $t->id);
         }
     } else {
         $alltags = Tag::model()->findAll(array('order' => 'data_count'));
         foreach ((array) $alltags as $tv) {
             $tag_ids[] = $tv->id;
         }
     }
     $ajax = Yii::app()->request->getParam('ajax');
     $data = array();
     $searchData = array();
     if ($tag_ids && $ajax == 1) {
         $td = new TagData();
         $condition = "status = 'Y'";
         $criteria = new CDbCriteria();
         $criteria->condition = $condition;
         $criteria->addInCondition('tag_id', $tag_ids);
         //分页
         $count = $td->count($criteria);
         $pages = new CPagination($count);
         $pages->pageSize = 10;
         $criteria->limit = $pages->pageSize;
         $criteria->offset = $pages->currentPage * $pages->pageSize;
         $tddata = $td->findAll($criteria);
         foreach ((array) $tddata as $value) {
             $modelType = ModelType::model()->findByPk($value->type);
             $model = $modelType->model;
             $c = $model::model()->findByPk($value->content_id, array('select' => 'id,title'));
             if ($c) {
                 $data[] = array('type' => $modelType->type_key, 'data' => $c);
             }
         }
         foreach ($data as $key => $new) {
             $searchData[$key]['url'] = $this->controller->createUrl("{$new['type']}/view", array('id' => $new['data']['id']));
             $searchData[$key]['title'] = $new['data']['title'];
         }
     }
     exit(CJSON::encode($searchData));
 }
Пример #3
0
 /**
  * ajax搜索
  */
 public function actionAjax()
 {
     $tags = trim($this->_request->getParam('tag'));
     $tags = preg_replace('/(\\s)+/', ',', trim($tags));
     $arr_tag = explode(',', $tags);
     foreach ((array) $arr_tag as $tag) {
         $t = Tag::model()->find('tag_name = :tn', array(':tn' => $tag));
         $t && ($tag_ids[] = $t->id);
     }
     $ajax = $this->_request->getParam('ajax');
     $data = array();
     $searchData = array();
     if ($tag_ids && $ajax == 1) {
         $td = new TagData();
         $condition = "status = 'Y'";
         $criteria = new CDbCriteria();
         $criteria->condition = $condition;
         $criteria->addInCondition('tag_id', $tag_ids);
         //分页
         $count = $td->count($criteria);
         $pages = new CPagination($count);
         $pages->pageSize = 10;
         $criteria->limit = $pages->pageSize;
         $criteria->offset = $pages->currentPage * $pages->pageSize;
         $tddata = $td->findAll($criteria);
         foreach ((array) $tddata as $value) {
             $modelType = ModelType::model()->findByPk($value->type);
             $model = $modelType->model;
             $value['type'] = $modelType->type_key;
             $value['data'] = $model::model()->findByPk($value->content_id, '', array('select' => 'id,title'));
             $data[] = $value;
         }
         foreach ($data as $key => $new) {
             $searchData[$key]['url'] = $this->createUrl("{$new->type}/view", array('id' => $new->data->id));
             $searchData[$key]['title'] = $new->data->title;
         }
     }
     exit(CJSON::encode($searchData));
 }