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


PHP models\Post類代碼示例

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


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

示例1: testGetPostsWithCategory

 public function testGetPostsWithCategory()
 {
     $category = $this->categoryModel->findOne(1);
     $expectedPosts = $category->getPosts();
     $actualPosts = $this->postModel->findAll(['category_id' => 1, 'publish_status' => Post::STATUS_PUBLISH]);
     $this->assertEquals($expectedPosts->count, count($actualPosts));
 }
開發者ID:richardcj,項目名稱:Blog-Yii2,代碼行數:7,代碼來源:CategoryTest.php

示例2: createPost

 public function createPost()
 {
     $newPost = new Post();
     $newPost['title'] = $this->title;
     $newPost['content'] = $this->content;
     $newPost['permit'] = $this->permit[0];
     if ($this->upload()) {
         $newPost['image'] = $this->thumbnail;
     }
     if ($this->date == "") {
         $newPost['create_at'] = date("Y-m-d");
     } else {
         $newPost['create_at'] = $this->date;
     }
     $newPost['user_id'] = $this->user_id;
     $newPost->save();
     if ($newPost['permit'] == 2) {
         foreach ($this->reader as $userId) {
             $newPostProtected = new PostProtected();
             $newPostProtected['create_at'] = $newPost['create_at'];
             $newPostProtected['post_id'] = $newPost['id'];
             $newPostProtected['user_id'] = $userId;
             $newPostProtected->save();
         }
     }
 }
開發者ID:ockor,項目名稱:yii2adv-blog,代碼行數:26,代碼來源:PostCreateForm.php

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

示例4: testSetTags

 public function testSetTags()
 {
     $sourceTags = [1, 3];
     $post = $this->postModel->findOne(2);
     $post->setTags($sourceTags);
     $this->assertInstanceOf('common\\models\\Post', $post);
     $this->assertTrue($post->save(false));
     $this->assertEquals($sourceTags, $post->getTags());
 }
開發者ID:richardcj,項目名稱:Blog-Yii2,代碼行數:9,代碼來源:PostTest.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

 /**
  * 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

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

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

示例9: actionCreate

 public function actionCreate()
 {
     //$start = microtime();
     parent::actionIndex();
     $postId = (int) Yii::$app->getRequest()->post('post_id');
     $url = Yii::$app->getRequest()->post('post_url');
     if ($postId && $postId != "undefined") {
         $post = Post::findByMySqlId($postId, Yii::$app->getRequest()->post('project_id'));
     } elseif ($url) {
         $post = Post::findByUrl($url);
     } else {
         throw new ForbiddenHttpException("Param url is not provided", self::CODE_NO_URL);
     }
     $postViewModel = new PostView();
     $postViewModel->load(Yii::$app->getRequest()->getBodyParams(), '');
     $postViewModel->post_id = $postId;
     $postViewModel->save();
     if ($post) {
         $total = PostView::find()->where(array('project_id' => (int) Yii::$app->getRequest()->post('project_id'), 'post_id' => $postId))->count();
         //$unique = PostView::find()->where(array('project_id' => (int)Yii::$app->getRequest()->post('project_id'), 'post_id' => (int)$post->getID()))->distinct("uid");
         $response = array('total' => $total, 'unique' => (int) $post->views['unique']);
         $post->views = $response;
         $post->save();
     } else {
         $total = PostView::find()->where(array('project_id' => (int) Yii::$app->getRequest()->post('project_id'), 'post_id' => $postId, 'post_url' => $url))->count();
         $response = array('total' => $total, 'unique' => 0);
     }
     //echo microtime() - $start;
     return $response;
 }
開發者ID:veretilosergei1985,項目名稱:learni,代碼行數:30,代碼來源:ViewController.php

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

示例11: actionIndex

 public function actionIndex()
 {
     $searchModel = new TweetSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $dataProvider->query->andWhere([Post::tableName() . '.type' => Tweet::TYPE, 'status' => [Post::STATUS_ACTIVE, Post::STATUS_EXCELLENT]]);
     $model = new Tweet();
     return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
開發者ID:tqsq2005,項目名稱:getyii,代碼行數:8,代碼來源:DefaultController.php

示例12: getPosts

 public function getPosts($isPublished = true)
 {
     $query = $this->hasMany(Post::className(), ['cid' => 'cid'])->with('categories')->with('tags')->with('author')->orderByCid();
     if ($isPublished) {
         $query = $query->published();
     }
     return $query->viaTable(Relationship::tableName(), ['mid' => 'mid']);
 }
開發者ID:Penton,項目名稱:MoBlog,代碼行數:8,代碼來源:Meta.php

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

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

示例15: findModel

 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('您所請求的頁麵不存在');
     }
 }
開發者ID:whystic,項目名稱:yii2-whystic-blog,代碼行數:15,代碼來源:HomeController.php


注:本文中的common\models\Post類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。