当前位置: 首页>>代码示例>>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;未经允许,请勿转载。