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


PHP Post::find方法代码示例

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


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

示例1: init

 public function init()
 {
     $newPosts = Post::find()->selectNoText()->recentPublished(3)->all();
     foreach ($newPosts as $post) {
         $this->_htmlStr .= Html::tag('div', Html::a($post->title, ['site/post', 'id' => $post->cid], ['class' => 'post-title']) . Html::tag('div', \Yii::$app->formatter->asDate($post->created), ['class' => 'date']), ['class' => 'recent-single-post']);
     }
 }
开发者ID:Penton,项目名称:MoBlog,代码行数:7,代码来源:NewPosts.php

示例2: actionIndex

 /**
  * @return string
  */
 public function actionIndex()
 {
     /* @var $postType PostType */
     /* @var $post Post */
     /* @var $taxonomies Taxonomy[] */
     /* @var $taxonomy Taxonomy */
     /* @var $lastMedia Media */
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     $postTypes = PostType::find()->select(['id', 'post_type_slug'])->all();
     $taxonomies = Taxonomy::find()->select(['id', 'taxonomy_slug'])->all();
     $items = [];
     foreach ($postTypes as $postType) {
         if (!isset($this->_option['post_type'][$postType->id]['enable']) || !$this->_option['post_type'][$postType->id]['enable']) {
             continue;
         }
         if ($post = $postType->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one()) {
             $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
             $query = $postType->getPosts()->andWhere(['post_status' => 'publish']);
             $countQuery = clone $query;
             $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
             for ($i = 1; $i <= $pages->pageCount; $i++) {
                 $items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'p', 'slug' => $postType->post_type_slug, 'page' => $i]), 'lastmod' => $lastmod->format('r')];
             }
         }
     }
     foreach ($taxonomies as $taxonomy) {
         if (!isset($this->_option['taxonomy'][$taxonomy->id]['enable']) || !$this->_option['taxonomy'][$taxonomy->id]['enable']) {
             continue;
         }
         if ($terms = $taxonomy->terms) {
             $post = Post::find()->from(['post' => Post::tableName()])->innerJoinWith(['terms' => function ($query) {
                 /* @var $query \yii\db\ActiveQuery */
                 $query->from(['term' => Term::tableName()]);
             }])->where(['IN', 'term.id', ArrayHelper::getColumn($terms, 'id')])->andWhere(['post.post_status' => 'publish'])->orderBy(['post.id' => SORT_DESC])->one();
             if ($post) {
                 $query = $taxonomy->getTerms();
                 $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
                 $countQuery = clone $query;
                 $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
                 for ($i = 1; $i <= $pages->pageCount; $i++) {
                     $items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'c', 'slug' => $taxonomy->taxonomy_slug, 'page' => $i]), 'lastmod' => $lastmod->format('r')];
                 }
             }
         }
     }
     if (isset($this->_option['media']['enable']) && $this->_option['media']['enable']) {
         $query = Media::find();
         $countQuery = clone $query;
         $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
         if ($lastMedia = $query->orderBy(['id' => SORT_DESC])->one()) {
             $lastmod = new \DateTime($lastMedia->media_modified, new \DateTimeZone(Option::get('time_zone')));
             for ($i = 1; $i <= $pages->pageCount; $i++) {
                 $items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'm', 'slug' => 'media', 'page' => $i]), 'lastmod' => $lastmod->format('r')];
             }
         }
     }
     return $this->renderPartial('index', ['items' => $items]);
 }
开发者ID:tampaphp,项目名称:app-cms,代码行数:63,代码来源:DefaultController.php

示例3: getMenu

 /**
  * @return array
  */
 protected function getMenu()
 {
     $menu = Post::find()->with(['currentTranslate' => function (ActiveQuery $q) {
         $q->select(['post_id', 'lang_id', 'title'])->asArray();
     }])->orderBy(['slug' => SORT_ASC])->all();
     return ArrayHelper::map($menu, 'slug', 'title');
 }
开发者ID:lav45,项目名称:yii2-translated-behavior-demo,代码行数:10,代码来源:SiteController.php

示例4: run

 /**
  * Displays a model.
  * @param string $id the primary key of the model.
  * @return \yii\db\ActiveRecordInterface the model being displayed
  */
 public function run($id)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $model = $this->findModel($id);
     $result = \common\models\Post::find()->where(['category_id' => $id])->all();
     return $result;
 }
开发者ID:veretilosergei1985,项目名称:learni,代码行数:12,代码来源:ViewAction.php

示例5: actionIndex

 public function actionIndex()
 {
     echo "Sending letters to subscribers begin...\n";
     $currentDayTime = time() - 60 * 60 * 24;
     $currentDay = date("Y-m-d H:i:s", $currentDayTime);
     $importantPosts = Post::find()->where(['is_public' => 1, 'is_index' => 1])->andWhere(['>', 'created_at', $currentDay])->orderBy(['created_at' => SORT_DESC])->limit(3)->all();
     $ids = [];
     foreach ($importantPosts as $post) {
         $ids[] = $post->id;
     }
     $maxCommentsPosts = Post::find()->where(['is_public' => 1])->andWhere(['>', 'created_at', $currentDay])->andWhere(['not in', "id", $ids])->orderBy(['id' => SORT_DESC])->limit(3)->all();
     $posts = array_merge($importantPosts, $maxCommentsPosts);
     // sending
     $subscribings = Subscribing::find()->all();
     $count = 0;
     foreach ($subscribings as $subscribing) {
         if (!filter_var($subscribing->email, FILTER_VALIDATE_EMAIL)) {
             echo "Email is not correct: " . $subscribing->email . "\n";
             $subscribing->delete();
             continue;
         }
         $unsubscribeKey = md5($subscribing->id . $subscribing->email);
         $message = Yii::$app->mailer->compose('subscribe-view-html', compact('posts', 'unsubscribeKey'))->setTo($subscribing->email)->setSubject('Новости Динамо');
         $send = $message->send();
         if ($send) {
             $count++;
         }
     }
     echo "Posted {$count} letters. \n";
     echo "Sending letters to subscribers end.\n";
 }
开发者ID:alexsynytskiy,项目名称:Dynamomania,代码行数:31,代码来源:SubscribingController.php

示例6: run

 public function run()
 {
     parent::run();
     // TODO: Change the autogenerated stub
     $nodes = Post::find()->where(['status' => 10])->limit(3)->all();
     return $this->render('PostBottomTopWidget', ['nodes' => $nodes]);
 }
开发者ID:nguyentuansieu,项目名称:BioMedia,代码行数:7,代码来源:PostBottomTopWidget.php

示例7: actionPost

 public function actionPost($id)
 {
     $post = Post::find()->andWhere(['cid' => $id])->published()->one();
     if (!$post) {
         throw new NotFoundHttpException('页面不存在');
     }
     return $this->render('post', ['post' => $post]);
 }
开发者ID:Penton,项目名称:MoBlog,代码行数:8,代码来源:SiteController.php

示例8: getPost

 private static function getPost($categoryID)
 {
     $postModel = Post::find()->where(['category_id' => $categoryID]);
     $count = $postModel->count();
     $pagination = new Pagination(['totalCount' => $count]);
     $nodes = $postModel->offset($pagination->offset)->limit($pagination->limit)->all();
     return ['nodes' => $nodes, 'pagination' => $pagination];
 }
开发者ID:nguyentuansieu,项目名称:phutungoto,代码行数:8,代码来源:CategoryController.php

示例9: actionIndex

 /**
  * 概要
  * @return string
  */
 public function actionIndex()
 {
     $recentPublishedPost = Post::find()->selectNoText()->recentPublished()->all();
     $postCount = Post::find()->published()->count();
     $categoryCount = Category::find()->count();
     //todo: 评论数量 最新回复
     return $this->render('index', ['recentPublishedPost' => $recentPublishedPost, 'postCount' => $postCount, 'categoryCount' => $categoryCount]);
 }
开发者ID:Penton,项目名称:MoBlog,代码行数:12,代码来源:SiteController.php

示例10: run

 public function run()
 {
     parent::run();
     // TODO: Change the autogenerated stub
     $post = new Post();
     $dataPartner = $post->find('image')->where(['category_id' => 18])->all();
     return $this->render('widget/partner', ['nodes' => $dataPartner]);
 }
开发者ID:nguyentuansieu,项目名称:phutungoto,代码行数:8,代码来源:PartnerWidget.php

示例11: actionUpdate

 /**
  * Updates an existing Post model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($tahun, $judul)
 {
     $model = Post::find()->where("tahun='" . $tahun . "' and title='" . $judul . "'")->one();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'tahun' => $model->tahun, 'judul' => $model->title]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
开发者ID:ilhammalik,项目名称:yii2-starter,代码行数:15,代码来源:PostController.php

示例12: actionIndex

 /**
  * @return string
  */
 public function actionIndex()
 {
     /* @var $lastPost \common\models\Post */
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     $lastPost = Post::find()->where(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one();
     return $this->renderPartial('index', ['title' => Option::get('sitetitle'), 'description' => Option::get('tagline'), 'link' => Yii::$app->request->absoluteUrl, 'lastBuildDate' => new \DateTime($lastPost->post_date, new \DateTimeZone(Option::get('time_zone'))), 'postTypes' => PostType::find()->all(), 'language' => Yii::$app->language, 'generator' => 'http://www.writesdown.com']);
 }
开发者ID:wozhen,项目名称:yii2-cms-writedown,代码行数:12,代码来源:FeedController.php

示例13: actionIndex

 public function actionIndex()
 {
     $topics = Post::find()->limit(20)->where(['status' => 2])->orderBy(['created_at' => SORT_DESC])->all();
     $users = UserService::findActiveUser(12);
     $statistics = array();
     $statistics['post_count'] = Post::find()->count();
     $statistics['comment_count'] = PostComment::find()->count();
     $statistics['online_count'] = Session::find()->where(['>', 'expire', time()])->count();
     return $this->render('index', ['topics' => $topics, 'users' => $users, 'statistics' => $statistics]);
 }
开发者ID:RanLee,项目名称:getyii,代码行数:10,代码来源:SiteController.php

示例14: actionRenderpage

 public function actionRenderpage($url)
 {
     $category = Category::findOne(['link' => $url]);
     if (empty($category)) {
         return $this->run('site/error');
     }
     $subcategories = Category::findAll(['parent' => $category->id]);
     $posts = Post::findAll(['category' => $category->id]);
     return $this->render('category', ['category' => $category, 'subcategories' => $subcategories, 'postsCount' => sizeof($posts), 'posts' => $posts, 'premiumPosts' => \common\models\Post::find()->where(['>', 'premium', date('d-m-Y H:i:s')])->andWhere(['category' => $category->id])->all()]);
 }
开发者ID:BoBRoID,项目名称:plochadka,代码行数:10,代码来源:SiteController.php

示例15: actionIndex

 public function actionIndex($page = 1)
 {
     $query = Post::find()->where('state_index = 1')->orderBy('created_datetime DESC');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 5, 'pageSize' => 5]);
     $allPosts = $query->offset($pages->offset)->limit($pages->limit)->all();
     $query = Post::find()->where('state_index = 1 AND main_flag = 1')->orderBy('created_datetime DESC');
     $mainPosts = $query->offset(0)->limit(2)->all();
     return $this->render('index', ['all_posts' => $allPosts, 'main_posts' => $mainPosts, 'pages' => $pages]);
 }
开发者ID:kibercoder,项目名称:bilious-octo-fibula,代码行数:10,代码来源:PostController.php


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