本文整理汇总了PHP中SSViewer::execute_string方法的典型用法代码示例。如果您正苦于以下问题:PHP SSViewer::execute_string方法的具体用法?PHP SSViewer::execute_string怎么用?PHP SSViewer::execute_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SSViewer
的用法示例。
在下文中一共展示了SSViewer::execute_string方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Small helper to render templates from strings
*/
public function render($templateString, $data = null)
{
if (!$data) {
$data = new SSViewerTestFixture();
}
return SSViewer::execute_string($templateString, $data);
}
示例2: testVersionedCache
public function testVersionedCache()
{
$origStage = Versioned::current_stage();
// Run without caching in stage to prove data is uncached
$this->_reset(false);
Versioned::reading_stage("Stage");
$data = new SSViewerCacheBlockTest_VersionedModel();
$data->setEntropy('default');
$this->assertEquals('default Stage.Stage', SSViewer::execute_string('<% cached %>$Inspect<% end_cached %>', $data));
$data = new SSViewerCacheBlockTest_VersionedModel();
$data->setEntropy('first');
$this->assertEquals('first Stage.Stage', SSViewer::execute_string('<% cached %>$Inspect<% end_cached %>', $data));
// Run without caching in live to prove data is uncached
$this->_reset(false);
Versioned::reading_stage("Live");
$data = new SSViewerCacheBlockTest_VersionedModel();
$data->setEntropy('default');
$this->assertEquals('default Stage.Live', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data));
$data = new SSViewerCacheBlockTest_VersionedModel();
$data->setEntropy('first');
$this->assertEquals('first Stage.Live', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data));
// Then with caching, initially in draft, and then in live, to prove that
// changing the versioned reading mode doesn't cache between modes, but it does
// within them
$this->_reset(true);
Versioned::reading_stage("Stage");
$data = new SSViewerCacheBlockTest_VersionedModel();
$data->setEntropy('default');
$this->assertEquals('default Stage.Stage', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data));
$data = new SSViewerCacheBlockTest_VersionedModel();
$data->setEntropy('first');
$this->assertEquals('default Stage.Stage', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data));
Versioned::reading_stage('Live');
$data = new SSViewerCacheBlockTest_VersionedModel();
$data->setEntropy('first');
$this->assertEquals('first Stage.Live', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data));
$data = new SSViewerCacheBlockTest_VersionedModel();
$data->setEntropy('second');
$this->assertEquals('first Stage.Live', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data));
Versioned::reading_stage($origStage);
}
示例3: process
/**
* Process the form that is submitted through the site
*
* @param array $data
* @param Form $form
*
* @return Redirection
*/
public function process($data, $form)
{
Session::set("FormInfo.{$form->FormName()}.data", $data);
Session::clear("FormInfo.{$form->FormName()}.errors");
foreach ($this->Fields() as $field) {
$messages[$field->Name] = $field->getErrorMessage()->HTML();
$formField = $field->getFormField();
if ($field->Required && $field->CustomRules()->Count() == 0) {
if (isset($data[$field->Name])) {
$formField->setValue($data[$field->Name]);
}
if (!isset($data[$field->Name]) || !$data[$field->Name] || !$formField->validate($form->getValidator())) {
$form->addErrorMessage($field->Name, $field->getErrorMessage(), 'bad');
}
}
}
if (Session::get("FormInfo.{$form->FormName()}.errors")) {
Controller::curr()->redirectBack();
return;
}
$submittedForm = Object::create('SubmittedForm');
$submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
$submittedForm->ParentID = $this->ID;
// if saving is not disabled save now to generate the ID
if (!$this->DisableSaveSubmissions) {
$submittedForm->write();
}
$values = array();
$attachments = array();
$submittedFields = new ArrayList();
foreach ($this->Fields() as $field) {
if (!$field->showInReports()) {
continue;
}
$submittedField = $field->getSubmittedFormField();
$submittedField->ParentID = $submittedForm->ID;
$submittedField->Name = $field->Name;
$submittedField->Title = $field->getField('Title');
// save the value from the data
if ($field->hasMethod('getValueFromData')) {
$submittedField->Value = $field->getValueFromData($data);
} else {
if (isset($data[$field->Name])) {
$submittedField->Value = $data[$field->Name];
}
}
if (!empty($data[$field->Name])) {
if (in_array("EditableFileField", $field->getClassAncestry())) {
if (isset($_FILES[$field->Name])) {
$foldername = $field->getFormField()->getFolderName();
// create the file from post data
$upload = new Upload();
$file = new File();
$file->ShowInSearch = 0;
try {
$upload->loadIntoFile($_FILES[$field->Name], $file, $foldername);
} catch (ValidationException $e) {
$validationResult = $e->getResult();
$form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
Controller::curr()->redirectBack();
return;
}
// write file to form field
$submittedField->UploadedFileID = $file->ID;
// attach a file only if lower than 1MB
if ($file->getAbsoluteSize() < 1024 * 1024 * 1) {
$attachments[] = $file;
}
}
}
}
$submittedField->extend('onPopulationFromField', $field);
if (!$this->DisableSaveSubmissions) {
$submittedField->write();
}
$submittedFields->push($submittedField);
}
$emailData = array("Sender" => Member::currentUser(), "Fields" => $submittedFields);
$this->extend('updateEmailData', $emailData, $attachments);
// email users on submit.
if ($recipients = $this->FilteredEmailRecipients($data, $form)) {
$email = new UserDefinedForm_SubmittedFormEmail($submittedFields);
$mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
if ($attachments) {
foreach ($attachments as $file) {
if ($file->ID != 0) {
$email->attachFile($file->Filename, $file->Filename, HTTP::get_mime_type($file->Filename));
}
}
}
foreach ($recipients as $recipient) {
$parsedBody = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
//.........这里部分代码省略.........
示例4: getEmail
public function getEmail($order = null)
{
$order = $order ?: $this->Order();
$email = Email::create();
$email->setTemplate($this->config()->email_template);
if ($this->Send_To) {
$email->setTo($this->Send_To);
} elseif (trim($order->Name)) {
$email->setTo($order->Name . ' <' . $order->LatestEmail . '>');
} else {
$email->setTo($order->LatestEmail);
}
if ($this->Send_From) {
$email->setFrom($this->Send_From);
} else {
if (\Config::inst()->get('OrderProcessor', 'receipt_email')) {
$adminEmail = \Config::inst()->get('OrderProcessor', 'receipt_email');
} else {
$adminEmail = \Email::config()->admin_email;
}
$email->setFrom($adminEmail);
}
$subject = $this->Send_Subject ? str_replace(['$Order.Reference', '$Order.ShippingAddress', '$Order.BillingAddress', '$Order.Customer.Name', '$Order.Total', '$Order.Items.count'], [$order->Reference, (string) $order->ShippingAddress(), (string) $order->BillingAddress(), $order->Customer() ? $order->Customer()->Name : 'Guest', $order->Total(), $order->Items()->count()], $this->Send_Subject) : _t('Order.RECEIPT_SUBJECT', 'Web Order - {reference}', ['reference' => $order->Reference]);
$email->setSubject($subject);
$note = $this->Send_Body ?: Object::create('BBCodeParser', $this->Note)->parse();
$email->populateTemplate(['Order' => $order, 'Member' => $order->Customer(), 'Note' => DBField::create_field('HTMLText', SSViewer::execute_string($note, $this, ['Order' => $order])), 'isPreview' => true]);
$this->extend('updateEmail', $email);
return $email;
}