当前位置: 首页>>代码示例>>PHP>>正文


PHP News::find方法代码示例

本文整理汇总了PHP中app\models\News::find方法的典型用法代码示例。如果您正苦于以下问题:PHP News::find方法的具体用法?PHP News::find怎么用?PHP News::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\News的用法示例。


在下文中一共展示了News::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionIndex

 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $query = News::find();
     $pagination = new Pagination(['defaultPageSize' => 4, 'totalCount' => $query->count()]);
     $news = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['news' => $news, 'pagination' => $pagination]);
 }
开发者ID:jeyfost,项目名称:jf,代码行数:12,代码来源:SiteController.php

示例2: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $cat)
 {
     if (Yii::$app->user->isGuest) {
         $isAdmin = false;
     } else {
         if (Yii::$app->user->identity->role == 1) {
             $isAdmin = true;
         } else {
             $isAdmin = false;
         }
     }
     if ($isAdmin) {
         $query = News::find();
     } else {
         $query = News::find()->where(['cat' => $cat]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['news_id' => $this->news_id, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'cat' => $this->cat, 'clickcnt' => $this->clickcnt]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
开发者ID:hehbhehb,项目名称:hongsong,代码行数:34,代码来源:NewsSearch.php

示例3: actionArticle

 public function actionArticle()
 {
     $id = $_GET['id'];
     $article = News::find()->where(["id" => $id])->one();
     // echo $id;
     return $this->render('article', ['article' => $article]);
 }
开发者ID:garydai,项目名称:yii2-demo,代码行数:7,代码来源:NewsController.php

示例4: actionIndex

 public function actionIndex()
 {
     //Записываем в переменную все новости из базы через модель
     $model = News::find()->all();
     //Передаем переменную представлению
     return $this->render('index', ['news' => $model]);
 }
开发者ID:andrewdemial,项目名称:news_task,代码行数:7,代码来源:SiteController.php

示例5: actionIndex

 public function actionIndex()
 {
     $news = News::find()->orderBy('createTime desc')->limit(3)->all();
     //  var_dump($news);
     //echo $news[0]->title;
     return $this->render('index', ['news' => $news]);
 }
开发者ID:garydai,项目名称:yii2-demo,代码行数:7,代码来源:SiteController.php

示例6: run

 public function run()
 {
     // query
     $news = News::find()->orderBy('date_news DESC')->limit(5)->all();
     // render view
     return $this->render('news', ['news' => $news]);
 }
开发者ID:highestgoodlikewater,项目名称:diplom,代码行数:7,代码来源:NewsWidget.php

示例7: actionIndex

 public function actionIndex($kinds = 'all')
 {
     $sort = new Sort(['attributes' => ['theme' => ['asc' => ['theme' => SORT_ASC], 'desc' => ['theme' => SORT_DESC], 'default' => SORT_ASC, 'label' => '主题'], 'author' => ['asc' => ['author' => SORT_ASC], 'desc' => ['author' => SORT_DESC], 'default' => SORT_DESC, 'label' => '作者'], 'reply' => ['asc' => ['reply' => SORT_ASC], 'desc' => ['reply' => SORT_DESC], 'default' => SORT_DESC, 'label' => '回复'], 'updated_at' => ['asc' => ['updated_at' => SORT_ASC], 'desc' => ['updated_at' => SORT_DESC], 'default' => SORT_DESC, 'label' => '最后更新'], 'plike' => ['asc' => ['plike' => SORT_ASC], 'desc' => ['plike' => SORT_DESC], 'default' => SORT_DESC, 'label' => '赞'], 'kinds' => ['asc' => ['kinds' => SORT_ASC], 'desc' => ['kinds' => SORT_DESC], 'default' => SORT_ASC, 'label' => '类别']], 'defaultOrder' => ['updated_at' => SORT_DESC]]);
     if ($kinds === 'all') {
         $query = Forum::find();
     } elseif ($kinds === 'tucao') {
         $query = Forum::find()->where(array('kinds' => 'tucao'));
     } elseif ($kinds === 'tactic') {
         $query = Forum::find()->where(array('kinds' => 'tactic'));
     } elseif ($kinds === 'rule') {
         $query = Forum::find()->where(array('kinds' => 'rule'));
     } elseif ($kinds === 'bug') {
         $query = Forum::find()->where(array('kinds' => 'bug'));
     } elseif ($kinds === 'team') {
         $query = Forum::find()->where(array('kinds' => 'team'));
     } elseif ($kinds === 'myposts') {
         //我发的帖子
         $query = Forum::find()->where(array('author' => Yii::$app->user->identity->username));
     } elseif ($kinds === 'myreplies') {
         //我回复的帖子
         $queryid = DetailForum::find()->select(['fatherindex'])->where(array('author' => Yii::$app->user->identity->username));
         $query = Forum::find()->where(array('id' => $queryid));
     } else {
         $query = Forum::find();
     }
     $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $query->count()]);
     $forums = $query->orderBy($sort->orders)->offset($pagination->offset)->limit($pagination->limit)->all();
     //用来置顶2个点赞量最高的
     $sort1 = new Sort(['attributes' => ['plike' => ['asc' => ['plike' => SORT_ASC], 'desc' => ['plike' => SORT_DESC], 'default' => SORT_DESC, 'label' => '赞']], 'defaultOrder' => ['plike' => SORT_DESC]]);
     $topquery = Forum::find()->orderBy($sort1->orders)->limit(2)->all();
     //用来置顶2个点赞量最高的
     $news = News::find()->orderBy('addedat')->all();
     return $this->render('index', ['new' => $news[0], 'forums' => $forums, 'pagination' => $pagination, 'sort' => $sort, 'topquery' => $topquery]);
 }
开发者ID:eesast,项目名称:ts17web,代码行数:34,代码来源:ForumController.php

示例8: actionGet_data

 public function actionGet_data()
 {
     //      var_dump($_POST);
     $count = News::find()->count();
     $connection = Yii::$app->db;
     $sql = "select * from news ";
     $condition = '';
     if ($_POST['searchPhrase'] != '') {
         $condition .= 'where title like ' . '"%' . $_POST['searchPhrase'] . '%" ';
     }
     if (isset($_POST['sort']['title'])) {
         $condition .= " order by title  {$_POST['sort']['title']} ";
     }
     $t = (intval($_POST['current']) - 1) * $_POST['rowCount'];
     $condition .= " limit {$t} , {$_POST["rowCount"]}";
     $sql .= $condition;
     # $criteria->limit = $_POST['rowCount'];
     # $criteria->offset= (intval($_POST['current']) -1)*$_POST['rowCount'];
     //  echo $sql;
     #$model = News::find()->all($criteria);
     //      var_dump($model);
     $model = $connection->createCommand($sql)->queryAll();
     $arr = array();
     foreach ($model as $o) {
         $json = array('id' => intval($o['id']), 'title' => $o['title']);
         array_push($arr, $json);
     }
     //var_dump( $arr);
     echo json_encode(array('rowCount' => $_POST['rowCount'], 'current' => $_POST['current'], 'rows' => $arr, 'total' => $count));
 }
开发者ID:garydai,项目名称:yii2.0-backend,代码行数:30,代码来源:NewsController.php

示例9: run

 public function run()
 {
     $query = News::find()->orderBy(['created_at' => SORT_DESC]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('news', ['models' => $models, 'pages' => $pages]);
 }
开发者ID:andreyvaslv,项目名称:crb,代码行数:8,代码来源:NewsList.php

示例10: show

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $news = News::find($id);
     if ($news->status_id != 3) {
         return redirect('/');
     }
     return view('front.news.show', compact('news'));
 }
开发者ID:svetlana-topalova,项目名称:news-portal,代码行数:13,代码来源:NewsController.php

示例11: actionIndex

 public function actionIndex()
 {
     $season = Season::findBySql('SELECT * FROM season WHERE invisible = 0 AND (unit1 != "" OR unit2 != "" OR unit3 != "" OR unit4 != "")')->all();
     $news = News::find()->where(['type' => '1'])->orderBy('id DESC')->one();
     $event = News::find()->where(['type' => '2'])->orderBy('id DESC')->one();
     $msgs = Chatmain::find()->orderBy('id DESC')->limit(50)->all();
     return $this->render('index', ['season' => $season, 'news' => $news, 'event' => $event, 'msgs' => $msgs]);
 }
开发者ID:Nechhist,项目名称:to.ru,代码行数:8,代码来源:SiteController.php

示例12: actionNews

 public function actionNews($news_id)
 {
     $news = News::find()->where(['id' => $news_id, 'is_published' => 1])->asArray()->one();
     if ($news) {
         $news['categories'] = CategoryRelations::get_news_categories_names($news['id']);
         return $this->render('news', compact('news'));
     }
 }
开发者ID:sahartak,项目名称:armbuy,代码行数:8,代码来源:SiteController.php

示例13: actionPage

 public function actionPage($view)
 {
     $page = Pages::findOne(['slug' => '/' . $view]);
     if ($page == null) {
         return $this->render('error');
     }
     $news = new ActiveDataProvider(['query' => News::find(), 'sort' => ['defaultOrder' => ['data_new' => SORT_DESC]], 'pagination' => ['pageSize' => 3, 'validatePage' => false]]);
     return $this->render('index', ['page' => $page, 'news' => $news]);
 }
开发者ID:hogvarce,项目名称:news_site,代码行数:9,代码来源:MainController.php

示例14: getLatestNews

 public static function getLatestNews()
 {
     $query = News::find()->orderBy('id desc');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $pages->defaultPageSize = 12;
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return ['models' => $models, 'pages' => $pages];
 }
开发者ID:huynt57,项目名称:bluebee-ng,代码行数:9,代码来源:News.php

示例15: actionAdmin

 public function actionAdmin($status = null)
 {
     $query = News::find()->orderBy('id DESC');
     if ($status !== null) {
         $query->andWhere(['status' => $status]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     return $this->render('admin', ['status' => $status, 'dataProvider' => $dataProvider]);
 }
开发者ID:Rudianasaja,项目名称:yiifeed,代码行数:9,代码来源:NewsController.php


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