如何在 phalcon 关系中按字段追加排序?
How to append sort by a field in phalcon relationship?
我有一种情况,我想按 recent upload
和 views
对我的视频博客进行排序,即按最近排序或按观看次数排序。我尝试了下面的代码,但现在我不知道下一步该做什么?
$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')
的事情?
从初始化函数中你可以看到我已经有一个顺序参数,它正在按降序获取视频博客,但是我希望它是动态的,这样我就可以传递类似 order by views 正如我上面提到的。
我的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>
您需要使用 getRelated(<relationshipName/Alias>, <array>parameters)
$category->getRelated('videoBlogs', [
'order' => 'created_at DESC'
]);
我有一种情况,我想按 recent upload
和 views
对我的视频博客进行排序,即按最近排序或按观看次数排序。我尝试了下面的代码,但现在我不知道下一步该做什么?
$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')
的事情?
从初始化函数中你可以看到我已经有一个顺序参数,它正在按降序获取视频博客,但是我希望它是动态的,这样我就可以传递类似 order by views 正如我上面提到的。
我的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>
您需要使用 getRelated(<relationshipName/Alias>, <array>parameters)
$category->getRelated('videoBlogs', [
'order' => 'created_at DESC'
]);