本文介绍了SilverStripe 3.1-页面创建和从前端发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们公司的Intranet,我创建了一个带有表单的页面,用于从前端创建电子邮件(创建新的电子邮件页面).

for our company intranet, I created a page with a Form to create an E-Mailing from the frontend (Create a New E-Mailing Page).

保存表单后,该页面应处于活动状态.我是这样做的,但是我认为我在某个地方犯了一个错误.因为KW1,KW2,Date和SendDate仅在我转到后端并再次单击发布"时才在前端可见.

The page should be Live after saving the form.I did it like this, but I think I made a mistake somewhere. Because KW1, KW2, Date and SendDate are only visible on the frontend if I go to the backend and click publish again.

public static $allowed_actions = array(
    'MailingForm'
);

public function MailingForm() {
    $date = new DateField('EndDate', 'Gültig bis');
    $date->setConfig('showcalendar', true);

    $sendDate = new DateField('SendDate', 'Versanddatum');
    $sendDate->setConfig('showcalendar', true);

    $fields = new FieldList(
        new TextField('Title', 'Title'),
        new TextField('KW1', 'Start KW'),
        new TextField('KW2', 'End KW'),
        $date,
        $sendDate
    );

    $actions = new FieldList(
        new FormAction('createMailing', 'Erstellen')
    );

    //$validator = new RequiredFields('Title');

    return new Form($this, 'MailingForm', $fields, $actions);//, $validator);
}

public function createMailing($data, $form) {
    $member = Member::currentUser();
    $filter = new URLSegmentFilter();

    $page = new Mailing();
    $form->saveInto($page);
    $page->PublisherID = $member->ID;
    $page->AuthorID = $member->ID;
    $page->ParentID = $this->ID;
    $page->URLSegment = $filter->filter($page->Title);
    $page->writeToStage('Stage');
    $page->publish('Stage', 'Live');

    // EMAIL BEG
    $email = new Email();

    $email->setTo('mail@mail.de');
    $email->setFrom('intranet@mail.de');
    $email->setSubject('Neues E-Mailing für '.$this->Title);

    $messageBody = "
        <p>Neues E-Mailing wurde angelegt und wartet auf Freischaltung</p>
        <p><strong>Name:</strong> {$data['Title']}</p>
        <p><strong>KWs:</strong> {$data['KW1']} - {$data['KW2']}</p>
        <p><strong>Gültig bis:</strong> {$data['EndDate']}</p>
        <p><strong>Versanddatum:</strong> {$data['SendDate']}</p>
    ";
    $email->setBody($messageBody);
    $email->send();
    // EMAIL END

    return $this->redirect($this->Parent()->URLSegment.'/'.$this->URLSegment.'/'.$page->URLSegment);

}

如果我将$page->writeToStage('Stage'); $page->publish('Stage', 'Live');替换为$page->write(),则如果我将$page->write()添加到除我之外的其他两个目录中,则该页面未发布

If I replace $page->writeToStage('Stage'); $page->publish('Stage', 'Live'); with $page->write() than the page isn't published if i add $page->write() to the other two than i receive this error

有人可以在这里帮助我吗?

Can someone help me here?

提前谢谢

再次解决问题

如果我使用以下方式发布页面

If I publish the Page with

$page->write();
$page->writeToStage('Stage');
$page->publish('Stage', 'Live');

所有数据均已正确提交,但我收到以下错误 http://www. picbutler.de/bild/301819/erroroirpt.jpg ,并且该页面仅保存为实时版本.在后端中,该页面被标记为已从草稿中删除". 所以我认为这是正确的方向.

than all data is submitted correctly but I receive the following error http://www.picbutler.de/bild/301819/erroroirpt.jpg and the page is only saved as live version. In the backend the page is than marked as "deleted from draft". So I think this is the right direction.

如果我使用以下方式发布页面

If I publish the Page with

$page->writeToStage('Stage');
$page->publish('Stage', 'Live');

我没有收到任何错误,提交的数据出现在后端,但未显示在已发布的版本中.我必须在后端再次发布Page,以使数据在前端可见.

I receive no error, the submitted data appears in the backend BUT NOT in the published version. I have to publish the Page again in the backend to make the data visible in frontend.

那么有什么想法可以解决这个问题吗?

So any ideas how to fix this?

推荐答案

好的,一百万次尝试之后我明白了! :)对于其他陷入困境的人.

ok, a million tries later i got it! :)For everybody else who get stuck on this.

您只需要在编写后将活动页面还原到舞台上

You just need to restore the live page to stage after writing

$page->write();
$page->doRestoreToStage();

仅此而已:)

这篇关于SilverStripe 3.1-页面创建和从前端发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 22:36