本文整理汇总了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));
}
示例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));
}
示例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();
}
}
示例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;
}