0

我有一种情况,我想对我的视频博客进行排序recent uploadviews即按最近排序或按视图排序。我尝试了下面的代码,但现在我不知道下一步该怎么做?

$category = VideoBlogCategoryModel::getVideoBlogCategoryBySlug($categorySlug);
$category->getVideoBlogs(); // This is the relationship

初始化函数:

// Configure relation with VideoBlogModel
$this->hasMany('id', VideoBlogModel::class, 'category_id', array(
    'alias' => 'videoBlogs',
    'foreignKey' => true,
    'cxAction' => static::ACTION_CASCADE_DELETE,
    'params' => array(
        'order' => 'created_at DESC'
    )
));

我怎样才能做类似的事情$category->getVideoBlogs('order','views DESC')or $category->getVideoBlogs('order','created_at DESC')

从初始化函数中,您可以看到我已经有一个 order 参数,它按降序获取视频博客,但是我希望它是动态的,以便我可以传递类似于我上面提到的按视图排序的东西。

我的阿贾克斯:

// Sort By Recent and Views Feature
$('.cx_sort_video').change(function(e){
    // loading bar
    parameters.sort = $(this).val();
    ajaxLoadVideo(parameters);
});

按下拉列表排序:

<li class="list-inline-item">
    <span>SORT BY: </span>
    <select style="border:0px;" class="cx_sort_video">
        <option> RECENT</option>
        <option> VIEWS</option>
    </select>
</li>
4

1 回答 1

1

你需要使用getRelated(<relationshipName/Alias>, <array>parameters)

$category->getRelated('videoBlogs', [
    'order' => 'created_at DESC'
]);
于 2019-01-31T11:56:46.667 回答