本文整理汇总了PHP中Director::redirectBack方法的典型用法代码示例。如果您正苦于以下问题:PHP Director::redirectBack方法的具体用法?PHP Director::redirectBack怎么用?PHP Director::redirectBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Director
的用法示例。
在下文中一共展示了Director::redirectBack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doRegister
function doRegister($data, $form)
{
// Check for existing member emial address
if ($member = DataObject::get_one("Member", "'Email' = '" . Convert::raw2sql($data['Email']) . "'")) {
// Set error message
$form->AddErrorMessage('Email', "Sorry, that email address already exists. Please choose another.", 'bad');
// Set form data from submitted values
Session::set("FormInfo.Form_RegistrationForm.data", $data);
// Return back to form
return Director::redirectBack();
}
// Otherwise create new member and log them in
$Member = new Member();
$form->saveInto($Member);
$Member->write();
$Member->login();
// Find or create the 'user' group
if (!($userGroup = DataObject::get_one('Group', "Code = 'users'"))) {
$userGroup = new Group();
$userGroup->Code = "users";
$userGroup->Title = "Users";
$userGroup->Write();
$userGroup->Members()->add($Member);
}
// Add member to user group
$userGroup->Members()->add($Member);
// Get Profile page
if ($ProfilePage = DataObject::get_one('EditProfilePage')) {
return Director::redirect($ProfilePage->Link('?success=1'));
}
}
示例2: submit
function submit($data, $form)
{
// if rewards added and get it button clicked then validate and save to order object
if (isset($data['action_submit']) && isset($data['Quantity'])) {
Session::clear($this->controller->RewardsSessionKey());
foreach ($data['Quantity'] as $ProductID => $quantity) {
$item = $this->controller->newReward($ProductID, $quantity);
Session::set($this->controller->RewardsSessionKey($ProductID), serialize($item));
}
if ($this->controller->RewardsTotalPoints() > Page_Controller::MemberPointsBalance()) {
$this->sessionMessage('You do not have enough points to purchase these rewards.', 'error');
Director::redirectBack();
return;
}
$new_items = $this->controller->RewardItems();
}
//delete all existing reward items for this order
$order_items = $this->controller->Order()->RewardItems();
foreach ($order_items as $o_item) {
$o_item->delete();
}
// then flush rewards from session
Session::clear($this->controller->RewardsSessionKey());
//then link the reward items to the order
if (isset($new_items)) {
foreach ($new_items as $item) {
$item->write();
}
}
// then redirect to next step
Director::redirect($this->controller->Link() . 'checkoutstep/orderconfirmationandpayment/');
}
示例3: saveComplexTableField
/**
* Very ugly copy of the same method in ComplexTableField, but need a way to inject the extra data into created
* objects prior to writing them.
*/
function saveComplexTableField($data, $form, $params)
{
$className = $this->sourceClass();
$childData = new $className();
$form->saveInto($childData);
// Populate in the defaults as well.
foreach ($this->defaultValues as $key => $value) {
$childData->{$key} = $value;
}
$childData->write();
// Save the many many relationship if it's available
if (isset($data['ctf']['manyManyRelation'])) {
$parentRecord = DataObject::get_by_id($data['ctf']['parentClass'], (int) $data['ctf']['sourceID']);
$relationName = $data['ctf']['manyManyRelation'];
$componentSet = $parentRecord->getManyManyComponents($relationName);
$componentSet->add($childData);
}
if (isset($data['ctf']['hasManyRelation'])) {
$parentRecord = DataObject::get_by_id($data['ctf']['parentClass'], (int) $data['ctf']['sourceID']);
$relationName = $data['ctf']['hasManyRelation'];
$componentSet = $parentRecord->getComponents($relationName);
$componentSet->add($childData);
}
$referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
$closeLink = sprintf('<small><a href="%s" onclick="javascript:window.top.GB_hide(); return false;">(%s)</a></small>', $referrer, _t('ComplexTableField.CLOSEPOPUP', 'Close Popup'));
$message = sprintf(_t('ComplexTableField.SUCCESSADD', 'Added %s %s %s'), $childData->singular_name(), '<a href="' . $this->Link() . '/item/' . $childData->ID . '/edit">' . $childData->Title . '</a>', $closeLink);
$form->sessionMessage($message, 'good');
Director::redirectBack();
}
示例4: addMember
function addMember($data, $form)
{
$member = new Member();
$form->saveInto($member);
$member->write();
Director::redirectBack();
}
示例5: Delete
public function Delete($data, $item)
{
if (!$item->canDelete()) {
$this->httpError(403);
}
$this->parent->{$this->name . 'ID'} = null;
$this->parent->write();
$item->delete();
return Director::is_ajax() ? $this->FieldHolder() : Director::redirectBack();
}
示例6: removeFromWishList
public function removeFromWishList($data, $form)
{
if (($member = Member::currentUser()) && ($wishListItems = $member->WishListItems("PageID = " . $data['PageID'])) && $wishListItems->exists()) {
foreach ($wishListItems as $wishListItem) {
$member->WishListItems()->remove($wishListItem);
}
}
//$page = DataObject::get_by_id("Page", $data['PageID']);
Director::redirectBack("?removed_wishlist=1");
}
示例7: fontAction
protected function fontAction($change)
{
$currentSize = $this->currentFontSize();
$currentSize = floatval($currentSize) + $change;
Session::set("fontsize", $currentSize);
if (Director::is_ajax()) {
return $this->CurrentFontSizeInPercentages($currentSize);
} else {
Director::redirectBack();
}
return array();
}
示例8: submit
/**
* Save the changes to the form
*/
function submit($data, $form, $request)
{
$member = Member::currentUser();
if (!$member) {
return false;
}
$form->saveInto($member);
$member->write();
$form->sessionMessage(_t("MemberForm.DETAILSSAVED", 'Your details have been saved'), 'good');
Director::redirectBack();
return true;
}
示例9: activate
function activate($data, $form, $request)
{
//Check if there's a temp member with a Verification Code equal to this
//if there is, register the new member and log him in
//if not, tell him the code is wrong
//Check if this member already exists
$tempMember = TempMember::codeExists($data);
if (!$tempMember) {
$form->sessionMessage(_t("Register.REGISTRATION ERROR", "There's no account waiting for activation with this code.\n\t\t\t\t\t\t\t\t\t If you already have an account log in here <a href=\"my-events/\">here</a>"), 'bad');
Director::redirectBack();
return;
}
// Create a new Member object
$member = new Member();
$member->FirstName = $tempMember->FirstName;
$member->Surname = $tempMember->Surname;
$member->Phone = $tempMember->Phone;
$member->Email = $tempMember->Email;
$member->Password = $tempMember->Password;
$member->ReceiveMail = $tempMember->ReceiveMail;
$member->ReceiveMail = $tempMember->ReceiveMail;
$member->RequestListedAsPresenter = $tempMember->RequestListedAsPresenter;
$member->LocationAddress = $tempMember->LocationAddress;
$member->LocationLatitude = $tempMember->LocationLatitude;
$member->LocationLongitude = $tempMember->LocationLongitude;
$member->Description = $tempMember->Description;
// Write to db.
// This needs to happen before we add it to a group
$member->write();
if ($tempMember->RequestListedAsPresenter) {
$presentorApproval = new PresentorApproval();
$presentorApproval->MemberID = $member->ID;
$presentorApproval->MemberName = $tempMember->FirstName . ' ' . $tempMember->Surname;
$presentorApproval->Message = $tempMember->Description;
$presentorApproval->Email = $tempMember->Email;
$presentorApproval->Confirmation = 'Pending';
$presentorApproval->IsDone = false;
$presentorApproval->write();
}
$tempMember->delete();
$member->logIn();
// Add the member to User Group
// Check if it exists first
if ($group = DataObject::get_one('Group', 'ID = 3')) {
$member->Groups()->add($group);
// Redirect based on URL
// TO EDIT
Director::redirect('SuccessVerification');
} else {
$form->sessionMessage(_t("Register.REGISTRATION ERROR", "Your registration wasn't successful please try again"), 'bad');
Director::redirectBack();
}
}
示例10: doProcess
public function doProcess($data, $form, $request)
{
$order = new Order();
$items = $order->Items();
$member = Member::currentUserID() ? Member::currentUser() : new Member();
$paymentClass = isset($data['PaymentMethod']) ? $data['PaymentMethod'] : null;
$payment = class_exists($paymentClass) ? new $paymentClass() : null;
$requirePayment = $order->Subtotal() > 0 ? true : false;
if (!($items && $items->Count() > 0)) {
$form->sessionMessage(_t('OrderForm.NOITEMS', 'Error placing order: You have no items in your cart.'), 'bad');
return Director::redirectBack();
}
if ($requirePayment) {
if (!($payment && $payment instanceof Payment)) {
user_error("OrderForm::doProcess(): '{$paymentClass}' is not a valid payment class!", E_USER_ERROR);
}
}
// Ensure existing members don't get their record hijacked (IMPORTANT!)
if (!$member->checkUniqueFieldValue($data)) {
$uniqueField = Member::get_unique_identifier_field();
$uniqueValue = $data[$uniqueField];
$uniqueError = "Error placing order: The %s \"%d\" is\n\t\t\t\talready taken by another member. If this belongs to you, please\n\t\t\t\tlog in first before placing your order.";
$form->sessionMessage(_t('EcommerceMemberExtension.ALREADYEXISTS', printf($uniqueError, strtolower($uniqueField), $uniqueValue), PR_MEDIUM, 'Let the user know that member already exists (e.g. %s could be "Email", %d could be "joe@somewhere.com)'), 'bad');
return Director::redirectBack();
}
$form->saveInto($member);
if (!$member->Password) {
$member->setField('Password', Member::create_new_password());
}
$member->write();
$form->saveInto($order);
try {
$result = $order->process($member->ID);
} catch (Exception $e) {
$form->sessionMessage(_t('OrderForm.PROCESSERROR', "An error occurred while placing your order: {$e->getMessage()}.<br>\n\t\t\t\t\tPlease contact the website administrator."), 'bad');
// Send an email to site admin with $e->getMessage() error
return Director::redirectBack();
}
if ($requirePayment) {
$form->saveInto($payment);
$payment->write();
$result = $payment->processPayment($data, $form);
if ($result->isSuccess()) {
$order->sendReceipt();
}
// Long payment process. e.g. user goes to external site to pay (PayPal, WorldPay)
if ($result->isProcessing()) {
return $result->getValue();
}
}
Director::redirect($order->Link());
}
示例11: finish
/**
* Handles validating the final step and writing the tickets data to the
* registration object.
*/
public function finish($data, $form)
{
parent::finish($data, $form);
$step = $this->getCurrentStep();
$datetime = $this->getController()->getDateTime();
$registration = $this->session->getRegistration();
$ticketsStep = $this->getSavedStepByClass('EventRegisterTicketsStep');
$tickets = $ticketsStep->loadData();
// Check that the requested tickets are still available.
if (!$this->validateTickets($tickets['Tickets'], $form)) {
Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
Director::redirectBack();
return false;
}
// Validate the final step.
if (!$step->validateStep($data, $form)) {
Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
Director::redirectBack();
return false;
}
// Reload the first step fields into a form, then save it into the
// registration object.
$ticketsStep->setForm($form);
$fields = $ticketsStep->getFields();
$form = new Form($this, '', $fields, new FieldSet());
$form->loadDataFrom($tickets);
$form->saveInto($registration);
if ($member = Member::currentUser()) {
$registration->Name = $member->getName();
$registration->Email = $member->Email;
}
$registration->TimeID = $datetime->ID;
$registration->MemberID = Member::currentUserID();
$total = $ticketsStep->getTotal();
$registration->Total->setCurrency($total->getCurrency());
$registration->Total->setAmount($total->getAmount());
foreach ($tickets['Tickets'] as $id => $quantity) {
if ($quantity) {
$registration->Tickets()->add($id, array('Quantity' => $quantity));
}
}
$registration->write();
$this->session->delete();
// If the registrations is already valid, then send a details email.
if ($registration->Status == 'Valid') {
EventRegistrationDetailsEmail::factory($registration)->send();
}
$this->extend('onRegistrationComplete', $registration);
return Director::redirect(Controller::join_links($datetime->Event()->Link(), 'registration', $registration->ID, '?token=' . $registration->Token));
}
示例12: process_payment_form_and_return_next_step
/**
* Process payment form and return next step in the payment process.
* Steps taken are:
* 1. create new payment
* 2. save form into payment
* 3. return payment result
*
* @param Order $order - the order that is being paid
* @param Form $form - the form that is being submitted
* @param Array $data - Array of data that is submittted
* @return Boolean - if successful, this method will return TRUE
*/
public static function process_payment_form_and_return_next_step($order, $form, $data)
{
if (!$order) {
$form->sessionMessage(_t('EcommercePayment.NOORDER', 'Order not found.'), 'bad');
Director::redirectBack();
return false;
}
$paidBy = $order->Member();
if (!$paidBy) {
$paidBy = Member::currentUser();
}
$paymentClass = !empty($data['PaymentMethod']) ? $data['PaymentMethod'] : null;
$payment = class_exists($paymentClass) ? new $paymentClass() : null;
if (!($payment && $payment instanceof Payment)) {
$form->sessionMessage(_t('EcommercePayment.NOPAYMENTOPTION', 'No Payment option selected.'), 'bad');
Director::redirectBack();
return false;
}
// Save payment data from form and process payment
$form->saveInto($payment);
$payment->OrderID = $order->ID;
if (is_object($paidBy)) {
$payment->PaidByID = $paidBy->ID;
}
$payment->Amount = $order->TotalOutstandingAsMoneyObject();
$payment->write();
// Process payment, get the result back
$result = $payment->processPayment($data, $form);
if (!$result instanceof Payment_Result) {
return false;
} else {
if ($result->isProcessing()) {
//IMPORTANT!!!
// isProcessing(): Long payment process redirected to another website (PayPal, Worldpay)
//redirection is taken care of by payment processor
return $result->getValue();
} else {
//payment is done, redirect to either returntolink
//OR to the link of the order ....
if (isset($data["returntolink"])) {
Director::redirect($data["returntolink"]);
} else {
Director::redirect($order->Link());
}
}
return true;
}
}
示例13: submit
function submit($data, $form)
{
if ($order = ShoppingCart::singleton()->current()) {
$package = $order->createShippingPackage();
$address = new Address();
$form->saveInto($address);
$estimator = new ShippingEstimator($package, $address);
$estimates = $estimator->getEstimates();
Session::set("ShippingEstimates", $estimates);
if (Director::is_ajax()) {
return json_encode($estimates->toArray());
//TODO: replace with an AJAXResponse class that can output to different formats
}
}
Director::redirectBack();
}
示例14: handleAction
function handleAction($request)
{
// This method can't be called without ajax.
if (!Director::is_ajax()) {
Director::redirectBack();
return;
}
// Protect against CSRF on destructive action
if (!SecurityToken::inst()->checkRequest($request)) {
return $this->httpError(400);
}
$actions = Object::get_static($this->class, 'batch_actions');
$actionClass = $actions[$request->param('BatchAction')];
$actionHandler = new $actionClass();
// Sanitise ID list and query the database for apges
$ids = split(' *, *', trim($request->requestVar('csvIDs')));
foreach ($ids as $k => $v) {
if (!is_numeric($v)) {
unset($ids[$k]);
}
}
if ($ids) {
$pages = DataObject::get('SiteTree', "\"SiteTree\".\"ID\" IN (" . implode(", ", $ids) . ")");
// If we didn't query all the pages, then find the rest on the live site
if (!$pages || $pages->Count() < sizeof($ids)) {
foreach ($ids as $id) {
$idsFromLive[$id] = true;
}
if ($pages) {
foreach ($pages as $page) {
unset($idsFromLive[$page->ID]);
}
}
$idsFromLive = array_keys($idsFromLive);
// Debug::message("\"SiteTree\".\"ID\" IN (" . implode(", ", $idsFromLive) . ")");
$livePages = Versioned::get_by_stage('SiteTree', 'Live', "\"SiteTree\".\"ID\" IN (" . implode(", ", $idsFromLive) . ")");
if ($pages) {
$pages->merge($livePages);
} else {
$pages = $livePages;
}
}
} else {
$pages = new DataObjectSet();
}
return $actionHandler->run($pages);
}
示例15: SaveProfile
/**
* @param $data
* @param $form
* @return SS_HTTPResponse
*/
function SaveProfile($data, $form)
{
// Check for a logged in member
if ($CurrentMember = Member::currentUser()) {
// Check for another member with the same email address
if ($member = DataObject::get_one("Member", "Email = '" . Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) {
$form->addErrorMessage("Name", 'Sorry, that name already exists.', "bad");
Session::set("FormInfo.Form_EditProfileForm.data", $data);
return Director::redirectBack();
} else {
$form->saveInto($CurrentMember);
$CurrentMember->write();
return $this->redirect($this->Link('?saved=1'));
}
} else {
return Security::PermissionFailure($this->controller, 'you must be logged in to edit your profile');
}
}