【发布时间】:2014-03-07 11:21:57
【问题描述】:
对于我们公司的 Intranet,我创建了一个带有表单的页面,用于从前端创建一个电子邮件(创建一个新的电子邮件页面)。
保存表单后页面应该是 Live 的。 我是这样做的,但我认为我在某个地方犯了错误。因为 KW1、KW2、Date 和 SendDate 只有在我转到后端并再次单击发布时才在前端可见。
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() 添加到其他两个而不是我收到此错误,则页面不会发布
在stage Stage中找不到[Title of Page]/[Page ID]
有人可以帮我吗?
提前谢谢你
再次分解问题
如果我发布页面
$page->write();
$page->writeToStage('Stage');
$page->publish('Stage', 'Live');
所有数据都正确提交,但我收到以下错误http://www.picbutler.de/bild/301819/erroroirpt.jpg 并且页面仅保存为实时版本。在后端页面被标记为“从草稿中删除”。 所以我认为这是正确的方向。
如果我发布页面
$page->writeToStage('Stage');
$page->publish('Stage', 'Live');
我没有收到任何错误,提交的数据出现在后端,但没有出现在发布的版本中。我必须在后端再次发布页面以使数据在前端可见。
那么有什么想法可以解决这个问题吗?
【问题讨论】:
-
对 ->doPublish() 有帮助吗?
-
只是在 $page->publish(...) 之后添加还是只做发布?
-
我会尝试
$page->write()然后$page->doPublish()就像@munomono 说的那样,doPublish()会解决你的问题。 -
嗨,好的,我添加了 write() 和 doPublish() 并删除了 writeToStage() 和 publish()。提交后我收到此错误picbutler.de/bild/301819/erroroirpt.jpg
-
尝试用 writeToStage 替换 write,然后 doPublish
标签: php forms silverstripe