當前位置: 首頁>>代碼示例>>PHP>>正文


PHP models\Article類代碼示例

本文整理匯總了PHP中common\models\Article的典型用法代碼示例。如果您正苦於以下問題:PHP Article類的具體用法?PHP Article怎麽用?PHP Article使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Article類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: insert

 /**
  * 將文章插入數據庫
  * @param $title
  * @param $content
  * @param $publish_at
  * @param $tag
  * @return bool
  */
 public static function insert($title, $content, $publish_at, $tag = '')
 {
     //插入標簽(搜索的分類)
     $article = new Article();
     $article->title = $title;
     $article->content = $content;
     $article->author = 'yang';
     $article->status = Article::STATUS_GATHER;
     $article->publish_at = $publish_at;
     $res = $article->save(false);
     if ($tag) {
         try {
             $tagModel = Tag::find()->where(['name' => $tag])->one();
             if (!$tagModel) {
                 $tagModel = new Tag();
                 $tagModel->name = $tag;
                 $tagModel->article_count = 0;
                 $tagModel->save(false);
             }
             $articleTag = new ArticleTag();
             $articleTag->article_id = $article->id;
             $articleTag->tag_id = $tagModel->id;
             $articleTag->save(false);
         } catch (\Exception $e) {
             echo $e->getMessage() . PHP_EOL;
         }
     }
     return $res ? true : false;
 }
開發者ID:specialnote,項目名稱:myYii,代碼行數:37,代碼來源:ArticleSpider.php

示例2: actionView

 public function actionView($id)
 {
     $article = Article::findOne($id);
     $comment = new Comment();
     $comments = $article->comments;
     return $this->render("view", ["article" => $article, "comment" => $comment, "comments" => $comments]);
 }
開發者ID:horechek,項目名稱:nnews,代碼行數:7,代碼來源:ArticleController.php

示例3: setStatus

 /**
  * 是否顯示狀態修改
  * @param $article_id
  * @param int $status
  * @return bool|int
  */
 public function setStatus($article_id, $status = 1)
 {
     if (!in_array($status, [0, 1])) {
         return false;
     }
     return Article::updateAll(['status' => $status], 'article_id = :article_id', [':article_id' => $article_id]);
 }
開發者ID:wordnews,項目名稱:wei_shop,代碼行數:13,代碼來源:Article.php

示例4: actionView

 public function actionView($id)
 {
     $this->view_data['article'] = $article = Article::find()->where("id = {$id}")->asArray()->one();
     //獲取這篇文章的所有留言
     $this->view_data['comments'] = Article::getComments($article['id']);
     return $this->render('view', $this->view_data);
 }
開發者ID:codekissyoung,項目名稱:filmfest,代碼行數:7,代碼來源:ArticleController.php

示例5: actionAddStars

 public function actionAddStars($id)
 {
     if (\Yii::$app->request->isAjax) {
         $model = Article::findOne($id);
         $model->addStars();
         return json_encode(1);
     }
 }
開發者ID:buuug7,項目名稱:game4039,代碼行數:8,代碼來源:ArticleController.php

示例6: findModel

 /**
  * 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.');
     }
 }
開發者ID:Brother-Simon,項目名稱:yii2-starter-kit,代碼行數:15,代碼來源:ArticleController.php

示例7: actionView

 /**
  * @param $slug
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionView($slug)
 {
     $model = Article::find()->published()->andWhere(['slug' => $slug])->one();
     if (!$model) {
         throw new NotFoundHttpException();
     }
     $viewFile = $model->view ?: 'view';
     return $this->render($viewFile, ['model' => $model]);
 }
開發者ID:dungphanxuan,項目名稱:yii2-starter-kit,代碼行數:14,代碼來源:ArticleController.php

示例8: actionDetail

 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]);
 }
開發者ID:specialnote,項目名稱:myYii,代碼行數:10,代碼來源:ArticleController.php

示例9: cache404Page

 /**
  * 生成 404 靜態頁麵
  * @author gaoqing
  * @date 2016-04-20
  * @param string $cacheKey 緩存的唯一標識
  * @return boolean$generateFlag是否生成成功
  */
 public static function cache404Page($cacheKey, $param = [], $forceCache = false)
 {
     $generateFlag = false;
     $frontend = \Yii::getAlias('@frontend');
     $page404FileName = $frontend . '/web/404.shtml';
     if (!file_exists($page404FileName)) {
         $forceCache = true;
     }
     if ($forceCache) {
         $view = "404";
         //獲取最新的資訊文章
         $article = new Article();
         $where = ' status=20';
         $order = ' articleid DESC';
         $lastestNews = $article->List_Articles($where, $order, 5, 0);
         //獲取 疾病健康 文章
         $darticle = new \common\models\disease\Article();
         $lastestJibingArticle = $darticle->getLatestArticle(5, 0);
         //精彩問答
         $ask = new Ask();
         $where1 = ' 1';
         $order1 = ' id DESC';
         $lastestAsk = $ask->getList($where1, $order1, 5, 0);
         //字母部分
         $letters = range('A', 'Z');
         $condition = array('typeid' => array(0, 2, 3, 4, 5, 6, 7, 8, 9));
         $rand_words = KeyWords::getCacheRandWords(100, $condition);
         //熱門疾病、熱門部位
         $commonDisDep = CacheHelper::getCache('frontend_article_detail_rmksbw_404', []);
         $params = ['lastestNews' => $lastestNews, 'lastestJibingArticle' => $lastestJibingArticle, 'lastestAsk' => $lastestAsk, 'letters' => $letters, 'rand_words' => $rand_words, 'commonDisDep' => $commonDisDep, 'searchurl' => 'http://www.9939.com/zhuanti/'];
         $controller = new BaseController('base404', null);
         $controller->id = "base404";
         $page404FilePath = $frontend . '/views/site';
         $controller->viewPath = $page404FilePath;
         $page404 = $controller->renderPartial($view, $params);
         if (isset($page404) && !empty($page404)) {
             if (file_put_contents($page404FileName, $page404)) {
                 $generateFlag = true;
             }
         }
     }
     return $generateFlag;
 }
開發者ID:VampireMe,項目名稱:admin-9939-com,代碼行數:50,代碼來源:CacheHelper.php

示例10: findModel

 /**
  * 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.');
     }
 }
開發者ID:wordnews,項目名稱:wei_shop,代碼行數:17,代碼來源:DownloadController.php

示例11: actionDelete

 /**
  * Deletes an existing ArticleCategory model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $articleModel = Article::find()->andWhere(['category_id' => $id])->one();
     if (null === $articleModel) {
         $this->findModel($id)->delete();
     } else {
         Yii::$app->session->setFlash('alert', ['body' => \Yii::t('backend', 'Can not delete category #' . $id . '. It used in other table. Change category for article #' . $articleModel->id . ' before delete.'), 'options' => ['class' => 'alert-error']]);
     }
     return $this->redirect(['index']);
 }
開發者ID:allhaze,項目名稱:renault,代碼行數:16,代碼來源:ArticleCategoryController.php

示例12: getMetaTags

 public static function getMetaTags()
 {
     $tags = [];
     $locale = null;
     $arr = self::parseUrl(Yii::$app->request->pathInfo);
     if (!empty($arr[0]) and !empty($arr[1]) and !empty($arr[2]) and !empty($arr[3])) {
         $shortLocale = $arr[0];
         $controller = $arr[1];
         $action = $arr[2];
         $slug = $arr[3];
         foreach (Yii::$app->params['availableLocales'] as $k => $v) {
             if ($shortLocale == explode('-', $k)[0]) {
                 $locale = $k;
             }
         }
         switch ($controller) {
             case 'page':
                 $model = self::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
                 break;
             case 'article':
                 $model = Article::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
                 break;
             case 'promo':
                 //$model = Promo::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
                 break;
             case 'project':
                 $model = Project::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
                 break;
         }
         //hardcore :) json to array
         if (!empty($model) and !empty($model->head)) {
             $arr = json_decode($model->head, true);
             foreach ($arr as $key => $value) {
                 foreach ($value as $key2 => $value2) {
                     //custom meta tag
                     if (4 == count($value2)) {
                         $value2 = array_values($value2);
                         $value2 = [$value2[0] => $value2[1], $value2[2] => $value2[3]];
                     }
                     $tags[] = $value2;
                 }
             }
         }
         if (empty($model)) {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
         if (!empty($tags[0]) and !empty($tags[0]['name']) and 'title' == !empty($tags[0]['name']) and !empty($tags[0]['content'])) {
             Yii::$app->view->title = $tags[0]['content'];
         } else {
             Yii::$app->view->title = $model->title;
         }
     }
     return $tags;
 }
開發者ID:efabrikov,項目名稱:qreachers,代碼行數:54,代碼來源:Page.php

示例13: search

 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find()->published();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'slug' => $this->slug, 'category_id' => $this->category_id]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
開發者ID:rocketyang,項目名稱:yii2-starter-kit,代碼行數:15,代碼來源:ArticleSearch.php

示例14: search

 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'slug' => $this->slug, 'author_id' => $this->author_id, 'category_id' => $this->category_id, 'updater_id' => $this->updater_id, 'status' => $this->status, 'published_at' => $this->published_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'body', $this->body]);
     return $dataProvider;
 }
開發者ID:efabrikov,項目名稱:qreachers,代碼行數:15,代碼來源:ArticleSearch.php

示例15: actionTag

 /**
  * Lists the Article models in a specific category $slug.
  *
  * @param $slug
  * @return mixed
  */
 public function actionTag($slug)
 {
     $model = Tag::find()->andWhere(['slug' => $slug])->one();
     if (!$model) {
         throw new NotFoundHttpException(Yii::t('frontend', 'Page not found.'));
     }
     $query = Article::find()->with('category')->joinWith('tags')->where('{{%tag}}.slug = :slug', [':slug' => $slug])->published();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 10]]);
     $dataProvider->sort = ['defaultOrder' => ['created_at' => SORT_DESC]];
     return $this->render('tag', ['model' => $model, 'dataProvider' => $dataProvider, 'menuItems' => self::getMenuItems()]);
 }
開發者ID:beaten-sect0r,項目名稱:yii2-core,代碼行數:17,代碼來源:ArticleController.php


注:本文中的common\models\Article類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。