Example #1
0
 public function actionView($id)
 {
     $article = Article::findOne($id);
     $comment = new Comment();
     $comments = $article->comments;
     return $this->render("view", ["article" => $article, "comment" => $comment, "comments" => $comments]);
 }
 /**
  * Finds the Article model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Article the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #3
0
 public function actionAddStars($id)
 {
     if (\Yii::$app->request->isAjax) {
         $model = Article::findOne($id);
         $model->addStars();
         return json_encode(1);
     }
 }
Example #4
0
 /**
  * Finds the ArticleDownload model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ArticleDownload the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     $ArticleDownload = ArticleDownload::findOne($id);
     $Article = Article::findOne($id);
     if ($ArticleDownload !== null && $Article !== null) {
         return ['ArticleDownload' => $ArticleDownload, 'Article' => $Article];
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #5
0
 public function actionDetail($id)
 {
     if (!($article = Article::findOne($id))) {
         throw new NotFoundHttpException('ID 为 ' . $id . ' 的文章没有找到');
     }
     //文章标签
     $tags = $article->getArticleTag();
     //相关文章
     return $this->render('detail', ['article' => $article, 'tags' => $tags]);
 }
Example #6
0
 public function init()
 {
     parent::init();
     if ($this->id) {
         $this->_item = Article::findOne($this->id);
     } else {
         throw new InvalidParamException(\Yii::t('front', 'No required parameter given') . ' - id');
     }
     if (!$this->articleType) {
         $this->articleType = 'normal';
     }
 }
Example #7
0
 /**
  * Deletes Article
  * @throws \Exception
  */
 public function deleteArticle()
 {
     /** @var $article Article */
     if ($article = Article::findOne($this->item_id)) {
         $article->removeAllTagValues();
         $article->delete();
     }
 }
Example #8
0
 public function init()
 {
     parent::init();
     $this->_article = Article::findOne($this->id);
 }
 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         // 跳转到 :您访问到页面不存在
     }
 }
Example #10
0
 public function actionArtedit()
 {
     if (Yii::$app->request->get('id')) {
         $id = Yii::$app->request->get('id');
         $cate = ArticleCate::find()->all();
         //类别数据填充
         $model = Article::findOne($id);
         return $this->render('artedit', ['id' => $id, 'cate' => $cate, 'model' => $model]);
     } elseif (Yii::$app->request->post('id')) {
         $id = Yii::$app->request->post('id');
         $model = Article::findOne($id);
         $cover = $model->cover;
         if ($model === null) {
             Yii::$app->getSession()->setFlash("info", '编辑失败');
             return $this->redirect(['articlelist']);
         }
         if ($model->load(Yii::$app->request->post())) {
             if ($_FILES['Article']['name']['cover']) {
                 //删除原图片
                 if ($cover) {
                     unlink($cover);
                 }
                 //更新新图片
                 $img = Yii::$app->imgload->UploadPhoto($model, 'uploads/article/', 'cover');
                 $model->cover = $img;
             } else {
                 $model->cover = $cover;
             }
             if ($model->save()) {
                 Yii::$app->getSession()->setFlash('info', '编辑成功!');
                 return $this->redirect(['articlelist']);
             } else {
                 Yii::$app->getSession()->setFlash('info', '编辑失败!');
                 @unlink($img);
                 return $this->redirect(['articlelist']);
             }
         }
     }
 }
 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('您要访问的页面不存在!');
     }
 }
Example #12
0
    echo Article::findOne(['id' => $model['recommend2_id']])->title;
    ?>
</p>
      </a></li>
  <?php 
}
?>
  <?php 
if (!empty($model['recommend3_id'])) {
    ?>
    <li><a href="<?php 
    echo \yii\helpers\Url::toRoute('/article/' . $model['recommend3_id'] . '-' . \Yii::$app->user->id);
    ?>
">
      <p><?php 
    echo Article::findOne(['id' => $model['recommend3_id']])->title;
    ?>
</p>
      </a></li>
  <?php 
}
?>
  </ul>
</div>
<div class="wycs"></div>
<script>
function closed()
{
 var aaa=document.getElementById("ad");
 aaa.style.display="none"
}