Silverstripe将Page写入Live,stage或Draft?这个怎么运作

时间:2015-08-16 03:59:00

标签: php silverstripe

通过选择版本来更新页面我有些困难...要创建,我这样做:

$PageCalendrierEvenement = new PageCalendrierEvenement();

$PageCalendrierEvenement->Title = $this->request->postVar('Titre');
$PageCalendrierEvenement->MenuTitle = $this->request->postVar('Titre');
$PageCalendrierEvenement->URLSegment = Utils::remplacerEspaces(Utils::remplacerAccents($PageCalendrierEvenement->Titre));
$PageCalendrierEvenement->publish('Stage');
$PageCalendrierEvenement->doRestoreToStage();

这项工作非常顺利。但我们怎样才能通过ID更新它的价值?是否可以使用DB:Query?

$evens = Versioned::get_by_stage('PageCalendrierEvenement', 'Stage')->byID($evenID);
$evens->Title = $this->request->postVar(Titre);
$evens->Publish('Stage');

1 个答案:

答案 0 :(得分:2)

对于SiteTree的子类,您可以这样做:

// Add element
private void Button_Click_4(object sender, RoutedEventArgs e)
{
    //add new item
    RadioButton obj = new RadioButton();
    obj.Content = "Group " + ++numberOfGroups;
    ListBox1.Items.Add(obj);

    //select last item
    int LastItemIndex = ListBox1.Items.Count - 1;
    ListBox1.SelectedItem = ListBox1.Items.GetItemAt(LastItemIndex);
}

// Remove element
private void Button_Click_5(object sender, RoutedEventArgs e)
{
    //delete selected item
    ListBox1.Items.RemoveAt(ListBox1.SelectedIndex);

    //select last item
    int LastItemIndex = ListBox1.Items.Count - 1;
    ListBox1.SelectedItem = ListBox1.Items.GetItemAt(LastItemIndex);
}

对于简单的DataObjects,您需要调用:

$evens = Versioned::get_by_stage('PageCalendrierEvenement', 'Stage')->byID($evenID);
$evens->Title = $this->request->postVar(Titre);

//do whatever you want...

$evens->doPublish(); //writes to Stage and Live and does other stuff for SiteTree

See source...