本文整理汇总了PHP中EntryManager::setFetchSortingField方法的典型用法代码示例。如果您正苦于以下问题:PHP EntryManager::setFetchSortingField方法的具体用法?PHP EntryManager::setFetchSortingField怎么用?PHP EntryManager::setFetchSortingField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntryManager
的用法示例。
在下文中一共展示了EntryManager::setFetchSortingField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sort
public function sort(&$sort, &$order, $params)
{
$section = $params['current-section'];
// If `?unsort` is appended to the URL, then sorting information are reverted
// to their defaults
if ($params['unsort']) {
$section->setSortingField($section->getDefaultSortingField(), false);
$section->setSortingOrder('asc');
redirect(Administration::instance()->getCurrentPageURL());
}
// By default, sorting information are retrieved from
// the filesystem and stored inside the `Configuration` object
if (is_null($sort) && is_null($order)) {
$sort = $section->getSortingField();
$order = $section->getSortingOrder();
// Sorting by ID requires saving sort data to the `EntryManager`
// object for subsequent use
if ($sort == 'id') {
EntryManager::setFetchSortingField('id');
EntryManager::setFetchSortingDirection($order);
}
} else {
// Ensure that this field is infact sortable, otherwise
// fallback to IDs
if (($field = FieldManager::fetch($sort)) instanceof Field && !$field->isSortable()) {
$sort = $section->getDefaultSortingField();
}
// If the sort order or direction differs from what is saved,
// update the config file and reload the page
if ($sort != $section->getSortingField() || $order != $section->getSortingOrder()) {
$section->setSortingField($sort, false);
$section->setSortingOrder($order);
redirect(Administration::instance()->getCurrentPageURL() . $params['filters']);
}
}
}