Exemplo n.º 1
0
 /**
  * @author: jason
  * @date: 2010-12-15下午01:51:35
  * @todo: 获得专家列表
  * @params:
  */
 public function getExpertList($limit = 5)
 {
     $expert_list = array();
     $expert_cate = Expert::model()->getCateList();
     // 先判断是否存在缓存,从缓存读取数据
     $model = new Expert();
     $key = $model->getExpertListCacheKey();
     $resource = Yii::app()->cache->get($key);
     if ($resource === false) {
         $connection = Yii::app()->db;
         $sql = " SELECT * FROM {{main_expert}} where is_delete = '0' and status= '1' ORDER BY is_top desc,sort desc  LIMIT {$limit} ";
         $command = $connection->createCommand($sql);
         $resource = $command->queryAll();
         // 设置缓存
         Yii::app()->cache->set($key, $resource);
     }
     if (!empty($resource)) {
         foreach ($resource as $one) {
             $id = $one['expert_id'];
             $expert_list[$id] = $one;
             $expert_list[$id]['cate'] = $expert_cate[$one['cate_id']];
             $expert_list[$id]['expert_intro'] = cutString($one['expert_intro'], 26);
             $model = new Show();
             $blog_link = $model->createCommendUrl('', 'home', $one['uid']);
             $expert_list[$id]['blog_link'] = empty($one['blog_link']) ? $blog_link : $one['blog_link'];
         }
     }
     return $expert_list;
 }