public function actionIndex() { $bannerList = Material::find()->where(['materialId' => Variable::$materialId_banner])->orderBy('sort ASC')->all(); $articleList = Article::find()->where(['categoryId' => Variable::$articleCat_type_news]); $articleList->orderBy('isIndexShow DESC'); $articleList = $articleList->limit(4)->all(); // print_r($bannerList); return $this->render(FVariable::$home_view, ['bannerList' => $bannerList, 'articleList' => $articleList]); }
public function actionIndex() { $categoryId = \Yii::$app->request->get('id'); $list = [Variable::$articleCat_type_good, Variable::$articleCat_type_nutrition, Variable::$articleCat_type_people]; if (!in_array($categoryId, $list)) { $categoryId = Variable::$articleCat_type_nutrition; } $model = Article::findOne(['categoryId' => $categoryId]); $modelList = Article::find()->where(['in', 'categoryId', $list])->all(); return $this->render(FVariable::$lifeIndex_view, ['model' => $model, 'modelList' => $modelList, 'id' => $categoryId]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Article::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(['like', '_id', $this->_id])->andFilterWhere(['like', 'user_id', $this->user_id])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'file', $this->file])->andFilterWhere(['like', 'share_to', $this->share_to])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
public function actionDetail() { $id = Yii::$app->request->get('id'); if (empty($id)) { $this->redirect(FVariable::$articleIndex_url); return; } (new Article())->updateArticleLookCount($id); $model = Article::findOne($id); $formerModel = Article::find()->where(['<', 'id', $id])->andWhere(['categoryId' => Variable::$articleCat_type_news])->orderBy('id DESC')->limit(1)->one(); $laterModel = Article::find()->where(['>', 'id', $id])->andWhere(['categoryId' => Variable::$articleCat_type_news])->orderBy('id DESC')->limit(1)->one(); return $this->render(FVariable::$articleDetail_view, ['model' => $model, 'formerModel' => $formerModel, 'laterModel' => $laterModel]); }
public function updateArticleLookCount($id) { $model = Article::findOne($id); if (!$model) { return false; } $cur = intval($model->lookCount); if ($cur < 1) { $cur = 0; } $model->lookCount = $cur + 1; if ($model->save()) { return true; } return false; }
public function actionView($id) { $model = Article::find()->where(['id' => $id, 'status' => Article::STATUS_ACTIVE])->one(); if ($model === null) { throw new NotFoundHttpException('not found'); } // 浏览量变化 $model->addView(); $commentModel = new Comment(); $commentQuery = Comment::find()->where(['article_id' => $id, 'parent_id' => 0]); $countCommentQuery = clone $commentQuery; $pages = new Pagination(['totalCount' => $countCommentQuery->count()]); $commentModels = $commentQuery->offset($pages->offset)->orderBy('created_at desc')->limit($pages->limit)->all(); $hots = Article::find()->where(['category_id' => $model->category_id])->limit(10)->orderBy('view desc')->all(); return $this->render('view', ['model' => $model, 'commentModel' => $commentModel, 'commentModels' => $commentModels, 'pages' => $pages, 'hots' => $hots]); }
/** * Creates data provider instance with search query applied * * @param array $params The search query params. * @param integer $pageSize The number of results to be displayed per page. * @param boolean $published Whether or not articles have to be published. * * @return ActiveDataProvider */ public function search($params, $pageSize = 3, $published = false) { $query = Article::find(); // this means that editor is trying to see articles // we will allow him to see published ones and drafts made by him if ($published === true) { $query->where(['status' => Article::STATUS_PUBLISHED]); $query->orWhere(['user_id' => Yii::$app->user->id]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => $pageSize]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'status' => $this->status, 'category' => $this->category]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'summary', $this->summary])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function actionUpdateArticle($id) { $userId = \Yii::$app->user->id; $model = Article::find()->where(['id' => $id, 'user_id' => $userId])->one(); $dataModel = ArticleData::find()->where(['id' => $id])->one(); if (!isset($model, $dataModel)) { throw new NotFoundHttpException('文章不存在!'); } if ($model->load(\Yii::$app->request->post()) && $dataModel->load(\Yii::$app->request->post())) { $isValid = $model->validate(); $isValid = $dataModel->validate() && $isValid; if ($isValid) { $model->save(false); $dataModel->save(false); \Yii::$app->session->setFlash('success', '修改成功,请等待管理员审核!'); return $this->redirect(['update-article', 'id' => $id]); } } return $this->render('update-article', ['model' => $model, 'dataModel' => $dataModel]); }
public function actionIndex() { \Yii::$app->response->format = Response::FORMAT_JSON; $userId = \Yii::$app->user->id; $id = \Yii::$app->request->get('id'); $type = \Yii::$app->request->get('type', 'article'); $action = \Yii::$app->request->get('action', 'up'); if ($type == 'article') { $model = Article::find()->where(['id' => $id])->select('id,up,down')->one(); } else { $model = Comment::find()->where(['id' => $id])->select('id,up,down')->one(); } $vote = Vote::find()->where(['type_id' => $id, 'type' => $type, 'action' => $action, 'user_id' => $userId])->one(); if (empty($vote)) { $model->{$action} += 1; $model->save(false); $vote = new Vote(); $params = ['type' => $type, 'action' => $action, 'type_id' => $id, 'user_id' => $userId]; $vote->attributes = $params; $vote->save(); } return ['up' => $model->up, 'down' => $model->down]; }
public function actionIndex() { $list = Article::findAll(['categoryId' => Variable::$articleCat_type_service]); return $this->render(FVariable::$serviceIndex_view, ['list' => $list]); }
/** * 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.'); } }
/** * @return \yii\db\ActiveQuery */ public function getArticles0() { return $this->hasMany(Article::className(), ['updater_id' => 'id']); }
public function findByArticleIdUpdate($articleId) { $articleList = Article::find()->where(array('id' => $articleId))->one(); $articleList->lookCount += 1; $articleList->update(); }
public function actionTeadetails() { $material = new Material(); $product = new Product(); $article = new Article(); $MaterialList = $material->findByProductId(GlobalArray::$productIdArray['0']); $ProductList = $product->findByProductId(GlobalArray::$productIdArray['0']); $articleList = $article->findById(GlobalArray::$productIdArray['0']); $product->UpdateByLookCount(GlobalArray::$productIdArray['0']); return $this->render(FVariable::$productTeadetails_view, ['MaterialList' => $MaterialList, 'ProductList' => $ProductList, 'articleList' => $articleList]); }