/** * 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]); }
/** * 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; }
public function actionArticle() { $id = $_GET['id']; $article = News::find()->where(["id" => $id])->one(); // echo $id; return $this->render('article', ['article' => $article]); }
public function actionIndex() { //Записываем в переменную все новости из базы через модель $model = News::find()->all(); //Передаем переменную представлению return $this->render('index', ['news' => $model]); }
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]); }
public function run() { // query $news = News::find()->orderBy('date_news DESC')->limit(5)->all(); // render view return $this->render('news', ['news' => $news]); }
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]); }
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)); }
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]); }
/** * 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')); }
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]); }
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')); } }
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]); }
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]; }
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]); }
public function actionIndex() { $page = Pages::findOne(['slug' => Yii::$app->request->url]); $news = new ActiveDataProvider(['query' => News::find()]); if ($page == null) { return $this->render('error'); } return $this->render('index', ['page' => $page, 'news' => $news]); }
public function actionIndex() { $categories = Category::find()->where(['status' => News::STATUS_ACTIVE])->orderBy('caption')->all(); $query = News::find()->joinWith('category')->where(['news.status' => News::STATUS_ACTIVE])->Andwhere(['category.status' => Category::STATUS_ACTIVE]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'defaultPageSize' => SiteController::DEFAULT_PAGE_SIZE]); $news = $query->offset($pagination->offset)->orderBy('date DESC')->limit($pagination->limit)->all(); return $this->render('index', ['categories' => $categories, 'news' => $news, 'pagination' => $pagination]); }
/** * Displays user profile * @param integer $id * @return mixed * @throws NotFoundHttpException */ public function actionView($id) { $user = User::findOne($id); if (!$user) { throw new NotFoundHttpException("No such user."); } $dataProvider = new ActiveDataProvider(['query' => News::find()->where(['user_id' => $id])->orderBy('id DESC'), 'pagination' => ['pageSize' => 10]]); return $this->render('view', ['model' => $user, 'dataProvider' => $dataProvider]); }
public function actionList() { $imgNews = News::getImgRecommendNewsByCategory(2, 5); $categoryId = Yii::$app->request->get('category_id'); $query = News::find()->where(['category_id' => $categoryId]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); $data = ['models' => $models, 'pages' => $pages, 'categoryId' => $categoryId, 'imgNews' => $imgNews]; return $this->render('list', ['data' => $data]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'image_id' => $this->image_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'date', $this->date])->andFilterWhere(['like', 'lang', $this->lang]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'published_at' => $this->published_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'body', $this->body]); return $dataProvider; }
/** * Search by request criteria. * * @param array|null Filter params. * @return ActiveDataProvider Data provider. */ public function search($params) { $query = News::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date_pub' => SORT_DESC]], 'pagination' => ['pageSize' => 50]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['status' => $this->status, 'DATE(date_pub)' => $this->date_pub]); $query->andFilterWhere(['like', 'news.title', $this->title]); return $dataProvider; }
public function getCount() { $query = News::find(); if (Common::getRole() == User::MODER) { $query->where(['status' => News::MODER_NEWS, 'category_id' => $this->getCategoryId()]); } elseif (Common::getRole() == User::SMODER) { $query->where(['status' => News::SMODER_NEWS, 'category_id' => $this->getCategoryId()]); } elseif (Common::getRole() == User::ADMIN) { $query->where(['status' => News::ADMIN_NEWS]); } return count($query->all()); }
public function actionIndex() { $categoryModel = Category::find()->All(); $projectModel = Project::find()->where(['show_in_index' => '1'])->limit(6)->all(); $customerModel = Customer::find()->All(); $applicationConfig = ApplicationConfig::find()->one(); $newsModel = News::find()->where(['show_in_index' => '1'])->limit(2)->all(); $galleryModel = Gallery::find()->orderBy(new Expression('rand()'))->limit(6)->all(); $visitor = ApplicationConfig::findOne(1); $visitor->visitors_count = $visitor->visitors_count + 1; $visitor->save(); return $this->render('index', ['categoryModel' => $categoryModel, 'projectModel' => $projectModel, 'customerModel' => $customerModel, 'applicationConfig' => $applicationConfig, 'newsModel' => $newsModel, 'galleryModel' => $galleryModel]); }
public function actionIndex($id = 1, $ajax = false) { $comment = new Comments(); $login = new login(); $news = News::find()->where(['id_category' => $id])->orderBy(['id' => SORT_DESC]); $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $news->count()]); $news = $news->offset($pagination->offset)->limit($pagination->limit)->all(); if ($ajax == true) { return $this->renderAjax('index', ['comment' => $comment, 'pagination' => $pagination, 'login' => $login, 'news' => $news]); } else { return $this->render('index', ['comment' => $comment, 'pagination' => $pagination, 'login' => $login, 'news' => $news]); } }
public function actionShow() { if (isset($_GET['name'])) { $name = $_GET['name']; $lang = \Yii::$app->language; //echo $name . ' - ' .$lang; $model = News::find()->where(['name' => $name, 'lang' => $lang])->one(); if ($model !== null) { //var_dump($model); return $this->render('show', ['model' => $model]); } } return $this->render('news_not_found'); }
public function actionIndex() { $query = News::find(); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 4]); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('index', ['models' => $models, 'pages' => $pages]); /*$query = News::getAll(); $pages = new Pagination(['totalCount' => count($query), 'pageSize' => 5,]); return $this->render('index', ['model' => $query, 'pages' => $pages,]);*/ }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find(); $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(['id' => $this->id, 'date' => $this->date, 'status' => $this->status, 'category_id' => $this->category_id]); $query->andFilterWhere(['like', 'headline', $this->headline])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'image', $this->image]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find(); $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(['id' => $this->id, 'date' => $this->date]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find(); $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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'excerpt', $this->excerpt])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }