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


PHP Article::find方法代碼示例

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


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

示例1: actionList

 public function actionList()
 {
     //$query = Article::find();$articles = Article::findAll(["status" => 1]);
     $query = Article::find()->with('comments');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $this->render("list", ["dataProvider" => $dataProvider]);
 }
開發者ID:horechek,項目名稱:nnews,代碼行數:7,代碼來源:ArticleController.php

示例2: actionIndex

 public function actionIndex()
 {
     //處理本頁麵按鈕操作
     $request = Yii::$app->request;
     if ($op = $request->get('op')) {
         //pubilsh article or not publish article
         $id = $request->get('id');
         $video = Article::find()->where(['id' => $id])->one();
         if ($op == 'p') {
             if ($video->status == 0) {
                 $video->status = 1;
             } else {
                 $video->status = 0;
             }
             $video->publish_time = date("Y-m-d H:i:s", time());
         }
         //delete article
         if ($op == 'd') {
             $video->status = -1;
         }
         $video->save(false);
     }
     //設置 where 語句
     $where = 'type = 2 and status != -1';
     $query = Article::find()->where($where);
     //使用分頁組件
     $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $query->count()]);
     //拿到視頻列表
     $videos = $query->orderBy('id')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['articles' => $videos, 'pagination' => $pagination, 'page' => Yii::$app->request->get('page')]);
 }
開發者ID:codekissyoung,項目名稱:filmfest,代碼行數:31,代碼來源:VideoController.php

示例3: 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

示例4: actionArticlelist

 public function actionArticlelist()
 {
     //分頁讀取類別數據
     $model = Article::find()->with('cate');
     $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $model->count()]);
     $model = $model->orderBy('id ASC')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('artlist', ['model' => $model, 'pagination' => $pagination]);
 }
開發者ID:dlpc,項目名稱:yii2-plane,代碼行數:8,代碼來源:ArticleController.php

示例5: actionUpdate

 /**
  * Updates an existing Article model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all(), 'ads' => Ad::find()->all(), 'articles' => Article::find()->all()]);
     }
 }
開發者ID:Brother-Simon,項目名稱:yii2-starter-kit,代碼行數:15,代碼來源:ArticleController.php

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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::find方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。