public function actionIndex() { $focusmap = Yii::app()->cache->get('aboutusfocusmap'); if($focusmap == false){ $focusmap = Img::model()->find(array( 'select'=>'path', 'condition'=>'typeid=5', 'order'=>'createtime desc', 'limit'=>'1', )); Yii::app()->cache->set('aboutusfocusmap',$focusmap,3600*24*30); } $aModel = new Article; //查询5条最新的莱斯新闻 $news = $aModel->findAll(array( 'select'=>'id,title', 'order'=>'sort desc,updatetime desc', 'limit'=>10, )); //根据ID 查询当前文章内容 $nid = isset($_GET['id'])?intval($_GET['id']):0; if($nid!=0){ $onenews = $aModel->find(array( 'select'=>'operator,title,content,updatetime', 'condition'=>"id=$nid", )); }else{ $this->render('404',array('msg'=>'你没有选择具体的新闻!')); exit; } $this->render('index',array( 'news'=>$news, 'focusmap'=>$focusmap, 'onenews'=>$onenews, )); }
public function actionIndex() { //分配焦点图 $focusmap = Yii::app()->cache->get('aboutusfocusmap'); if($focusmap == false){ $focusmap = Img::model()->find(array( 'select'=>'path', 'condition'=>'typeid=4', 'order'=>'createtime desc', 'limit'=>'1', )); Yii::app()->cache->set('aboutusfocusmap',$focusmap,3600*24*30); } //分配文章 isset($_GET['id'])?$id = intval($_GET['id']):$id=1; $model = Yii::app()->cache->get('Articles'.$id); if($model == false){ $model = $this->loadModel($id); Yii::app()->cache->set('Articles'.$id,$model,3600*24*30); } //分配文章项 $items = Yii::app()->cache->get('Articleitems'); if($items == false){ $items = News::model()->findAll(array( 'select'=>'id,title', 'condition'=>'id <> 1', )); Yii::app()->cache->set('Articleitems',$items,3600*24*30); } $this->render('index',array( 'model'=>$model, 'items'=>$items, 'focusmap'=>$focusmap, )); }
private function loadModel($id) { $model=Img::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { if (($cache = Yii::app()->cache) != null) { //标识字段,用来指向缓存中存储的一部分数据。 $key = 'ArticleView' . $id; if (($jsonObj = $cache->get($key)) != false) { echo $jsonObj; return; } } $artImg = new ArticleImage(); $article = $this->loadModel($id); $article->content = strip_tags($article->content); $article->content = trim($article->content); $article->title = str_replace(" ", "", $article->title); //$article->content=nl2br($article->content); //$article->content=str_replace("\n","",$article->content); //$order = array("\r\n", "\n", "\r"); $order = array("\n"); $replace = ''; $article->content = str_replace($order, $replace, $article->content); //$article->content=nl2br($article->content); //$article->content = ' '.preg_replace('/(\s){2,}/',"\r\n <br /> ",$article->content); $article->content = ' ' . preg_replace('/(\\s){2,}/', "\r\r<br />\n ", $article->content); $date = $article->create_time; $article->create_time = date('Y年m月d日', strtotime($article->create_time)); $artImg->article = $article; $easys = array(); $images = Img::model()->findAll('article_id=:article_id', array(':article_id' => $article->id)); foreach ($images as $image) { $easyImg = new EasyImg(); $easyImg->url = ImgRoot . $date . '/b_' . $image->url; array_push($easys, $easyImg); } $artImg->imgs = $easys; $comment = Comment::model()->find('article_id=:article_id', array(':article_id' => $article->id)); $artImg->ccount = count($comment) . ""; $easyComment = new EasyComment(); if ($comment) { $easyComment->content = $comment->content; $easyComment->create_time = $comment->create_time; $easyComment->nick = $comment->nick; } else { $easyComment->content = ""; $easyComment->create_time = ""; $easyComment->nick = ""; } $artImg->comment = $easyComment; $artImg->share = ShareRoot . 'share/share&i=' . $id . '&t=0&n=' . 'Article'; $jsonObj = CJSON::encode($artImg); if (isset($key)) { $cache->set($key, $jsonObj, 0, new CDbCacheDependency('select max(id) from tbl_dblogs')); } echo $jsonObj; }
<div class="post"> <h2><?php echo $model->title; ?> </h2> <h3><?php echo $model->subTitle; ?> </h3> <div class="post-meta"><?php echo "日期:" . $model->create_time; echo ' ' . $model->src; ?> </div> <?php $images = Img::model()->findAll('article_id=:article_id', array(':article_id' => $model->id)); foreach ($images as $image) { $url = ImgRoot . $model->create_time . '/b_' . $image->url; //$url=ImgRoot.$model->create_time.'/'.$image->url; ?> <div class="post-thumb"><img src=<?php echo $url; ?> alt=""/></div> <br> <?php } ?> <div class="post-content">
protected function getPictureFormImg($typdid,$count) { $pictures = Yii::app()->cache->get('picture'.$typdid.$count); if($pictures===false){ $pictures = Img::model()->findAll(array( 'select'=>'title,path,url,description', 'condition'=>"typeid=$typdid", 'limit'=>$count, 'order'=>'createtime desc', )); if(!empty($pictures)){ Yii::app()->cache->set('picture'.$typdid.$count,$pictures,3600*24); } } return $pictures; }