• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP models\Article类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中common\models\Article的典型用法代码示例。如果您正苦于以下问题:PHP Article类的具体用法?PHP Article怎么用?PHP Article使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Article类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find()->orderBy('created_at DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author]);
     return $dataProvider;
 }
开发者ID:kotmonstr,项目名称:kotmonstr,代码行数:18,代码来源:ArticleSearch.php


示例17: actionSearchList

 public function actionSearchList($q = null)
 {
     $out = [];
     if ($q) {
         $query = Article::find()->where(['LIKE', 'title', $q])->orWhere(['LIKE', 'body', $q]);
         $data = $query->limit(10)->all();
     }
     foreach ($data as $d) {
         $out[] = ['value' => $d['title']];
     }
     echo Json::encode($out);
 }
开发者ID:gouchaoer,项目名称:yii2-starter-kit,代码行数:12,代码来源:ArticleController.php


示例18: actionIndex

 public function actionIndex()
 {
     if (\Yii::$app->user->isGuest) {
         $this->redirect(['user/sign-in/login']);
     }
     $article = (new Query())->from('article')->all();
     $query = Article::find();
     $provide = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC, 'title' => 'simon']]]);
     $provide->prepare();
     $pagination = $provide->getPagination();
     return $this->render('index', ['article' => $provide->getModels(), 'pageCount' => $pagination->pageCount, 'page' => $pagination->page, 'links' => $pagination->getLinks()]);
 }
开发者ID:Brother-Simon,项目名称:yii2-starter-kit,代码行数:12,代码来源:SiteController.php


示例19: init

 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';
     }
 }
开发者ID:czechcamus,项目名称:dasport,代码行数:12,代码来源:NewsletterArticle.php


示例20: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find()->where(['in', 'status', [Article::STATUS_GATHER, Article::STATUS_DISPLAY]]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 100]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     if ($this->status) {
         $query->andFilterWhere(['like', 'status', $this->status]);
     }
     return $dataProvider;
 }
开发者ID:specialnote,项目名称:myYii,代码行数:20,代码来源:ArticleGatherSearch.php



注:本文中的common\models\Article类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP models\Category类代码示例发布时间:2022-05-23
下一篇:
PHP Model\CommonModel类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap