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


PHP Post::findAll方法代碼示例

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


在下文中一共展示了Post::findAll方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: testGetPublishedPosts

 public function testGetPublishedPosts()
 {
     $posts = $this->postModel->getPublishedPosts();
     $this->assertInstanceOf('yii\\data\\ActiveDataProvider', $posts);
     $count = $this->postModel->findAll(['publish_status' => Post::STATUS_PUBLISH]);
     $this->assertEquals($posts->count, count($count));
 }
開發者ID:richardcj,項目名稱:Blog-Yii2,代碼行數:7,代碼來源:PostTest.php

示例3: actionBulkDelete

 /**
  * Delete multiple existing Post model.
  * For ajax request will return json object
  * and for non-ajax request if deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionBulkDelete()
 {
     $request = Yii::$app->request;
     $pks = $request->post('pks');
     // Array or selected records primary keys
     foreach (Post::findAll(json_decode($pks)) as $model) {
         $model->delete();
     }
 }
開發者ID:hdushku,項目名稱:npai,代碼行數:16,代碼來源:PostController.php

示例4: getBlogPostsByRating

 /**
  * Get block with 3 blog posts, which are best by rating during last 3 months
  * @return array Data
  */
 public static function getBlogPostsByRating($cache = true)
 {
     if ($cache) {
         $cacheBlock = CacheBlock::find()->where(['machine_name' => 'blogPostsByRating'])->one();
         if (isset($cacheBlock)) {
             return ['view' => '@frontend/views/blocks/cache_block', 'data' => ['content' => $cacheBlock->content]];
         }
     }
     $connection = Yii::$app->db;
     $blogsIDQuery = 'SELECT id
                 FROM posts
                 WHERE created_at > DATE_SUB(NOW(), INTERVAL 90 day) AND content_category_id = ' . Post::CATEGORY_BLOG;
     //INNER JOIN votes ON post.id = votes.voteable_id AND votes.voteable_type = '.Vote::VOTEABLE_POST.'
     $cmd = $connection->createCommand($blogsIDQuery);
     $bestBlogs = $cmd->queryAll();
     $ratingArray = [];
     foreach ($bestBlogs as &$blog) {
         $blog['rating'] = Vote::getRating($blog['id'], Vote::VOTEABLE_POST);
     }
     for ($i = 0; $i < count($bestBlogs) - 1; $i++) {
         for ($j = $i + 1; $j < count($bestBlogs); $j++) {
             if ($bestBlogs[$j]['rating'] > $bestBlogs[$i]['rating']) {
                 $temp = $bestBlogs[$j];
                 $bestBlogs[$j] = $bestBlogs[$i];
                 $bestBlogs[$i] = $temp;
             }
         }
     }
     $count = 3;
     if (count($bestBlogs) < 3) {
         $count = count($bestBlogs);
     }
     $best3Blogs = [];
     for ($i = 0; $i < $count; $i++) {
         $best3Blogs[] = $bestBlogs[$i]['id'];
     }
     $blogs = Post::findAll($best3Blogs);
     $block = ['view' => '@frontend/views/blocks/blog_block_rating', 'data' => compact('blogs')];
     if (!$cache) {
         $view = new \yii\base\View();
         return $view->renderFile($block['view'] . '.php', $block['data']);
     }
     return $block;
 }
開發者ID:alexsynytskiy,項目名稱:Dynamomania,代碼行數:48,代碼來源:SiteBlock.php


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