/** * 文章页 * @author gaoqing * @date 2016-03-25 * @return string 视图 */ public function actionDetail() { $view = "detail"; $aid = $this->helpGparam("aid", "-1"); //获取文章的信息 $condition = ['id' => $aid]; $article = Article::search($condition, 0, 1); $article = $article['list']; if (!isset($article) || empty($article)) { throw new NotFoundHttpException('当前访问的页面不存在!'); } if ($this->isNotNull($article)) { $article = $article[0]; $article['inputtime'] = date('Y-m-d H:i:s', $article['inputtime']); $article['keywords_init'] = $article['keywords']; $article['keywords'] = explode(' ', $article['keywords']); } //文章内容添加疾病、症状词的链接 //lc@2016-5-24 $cache_all = Article::getAllDiseaseSymptom2Redis(); $content = $article['content']; $link_num = 5; //每页内链个数 $single_link_num = 1; //单个词链接个数 $i = 1; $str = ''; $count = 0; foreach ($cache_all as $k => $v) { $searchArr = '(' . $k . ')'; $replaceArr = '<a href="' . $v . '" title="' . $k . '" target="_blank">' . $k . '</a>'; if ($i > $link_num) { break; } if (stripos($str, $k) === false) { $content = preg_replace($searchArr, $replaceArr, $content, $single_link_num, $count); if ($count > 0) { $str .= $k; $i++; } } } $article['content'] = $content; //获取当前文章对应的疾病信息 $isSymptom = 0; if ($article['diseaseid'] > 0) { $disease_obj = new Disease(); $res = $disease_obj->getDiseaseById($article['diseaseid']); $disease = $res['disease']; $disease['inspect'] = $res['diseaseContent']['inspect']; } elseif ($article['symptomid'] > 0) { $symptom = Symptom::getSymptomByid($article['symptomid'], true); $disease = $symptom; $disease['inspect'] = $symptom['examine']; $isSymptom = 1; } //上一篇 $preCondition = ['<', 'id', $aid]; $preArticle = Article::search($preCondition, 0, 1, 'id DESC'); $preArticle = $preArticle['list']; if ($this->isNotNull($preArticle)) { $preArticle = $preArticle[0]; } //下一篇 $nextCondition = ['>', 'id', $aid]; $nextArticle = Article::search($nextCondition, 0, 1, 'id ASC'); $nextArticle = $nextArticle['list']; if ($this->isNotNull($nextArticle)) { $nextArticle = $nextArticle[0]; } $relArtsAndAsks = CacheHelper::getCache('frontend_article_detail_xgwz', ['title' => $article['title'], 'id' => $aid, 'diseaseid' => $article['diseaseid'], 'symptomid' => $article['symptomid']]); $relArticles = $relArtsAndAsks['relArticles']; //相关问答 $asks = $relArtsAndAsks['relAsks']; //hot words part $letter_list = range('A', 'Z'); $randwords = $this->rand_words(); $hotWords = ['letter' => $letter_list, 'words' => $randwords]; //common diseases and hot departments part $commonDisDep = CacheHelper::getCache('frontend_article_detail_rmksbw', []); //大家还在找部分 $stillFind = $this->getStillFindDatas($disease['name']); //右侧:最新文章 $lastestArticles = $this->getLatestArticles(); $params = ['article' => $article, 'preArticle' => $preArticle, 'nextArticle' => $nextArticle, 'relArticles' => $relArticles, 'asks' => $asks, 'isSymptom' => $isSymptom, 'disease' => $disease, 'hotWords' => $hotWords, 'commonDisDep' => $commonDisDep, 'stillFind' => $stillFind, 'lastestArticles' => $lastestArticles]; return $this->render($view, $params); }