有没有人知道如何在Silverstripe 3.2中修改DataList的阶段?我想修改网格字段组件中的DataList,以根据?_GET [' stage']参数进行更改。
答案 0 :(得分:1)
我解决了这个问题,如下所示。
class GridFieldChangeStage implements GridField_DataManipulator {
/*
* Modifies the DataList stage accordingly
*/
public function getManipulatedData(GridField $gridField, SS_List $dataList)
{
$isShowingLiveData = (isset($_GET['stage']) && $_GET['stage'] == 'Live');
if ($isShowingLiveData) {
$dataList = $dataList->alterDataQuery(function($dataQuery) {
$dataQuery->setQueryParam('Versioned.mode', 'stage');
$dataQuery->setQueryParam('Versioned.stage', 'Live');
});
}
return $dataList;
}
}