如何在Phalcon关系中按字段追加排序?

时间:2019-01-31 10:30:57

标签: php relationship phalcon phalcon-orm

我遇到一种情况,我想按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')$category->getVideoBlogs('order','created_at DESC')的事情?

从initialize函数中,您可以看到我已经具有一个订单参数,该参数正在按降序获取视频博客,但是我希望它是动态的,这样我就可以像我提到的那样通过按视图排序以上。

我的Ajax:

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

1 个答案:

答案 0 :(得分:1)

您需要使用Name age phonenumber akshatha 27 9900090252 amrutha 28 9900902423 sharath 29 9900902878

getRelated(<relationshipName/Alias>, <array>parameters)