本文整理汇总了PHP中Director::is_ajax方法的典型用法代码示例。如果您正苦于以下问题:PHP Director::is_ajax方法的具体用法?PHP Director::is_ajax怎么用?PHP Director::is_ajax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Director
的用法示例。
在下文中一共展示了Director::is_ajax方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: subscribe
/**
* Handles the action when subscribe is being done
*
* @param Array $data
* @param Form $form
*/
public function subscribe(array $data, Form $form)
{
$settings = SiteConfig::current_site_config();
$MailChimp = new \Drewm\MailChimp($settings->APIKey);
$apiData = array('id' => $settings->MailChimpList()->filter(array('Code' => 'NEWSLETTER'))->First()->ListID, 'email' => array('email' => $data['Email']), 'double_optin' => false, 'update_existing' => false, 'replace_interests' => false, 'send_welcome' => false);
$this->extend('updateAPIData', $apiData);
$result = $MailChimp->call('lists/subscribe', $apiData);
if (Director::is_ajax()) {
if (isset($result['status']) && $result['status'] == 'error') {
if ($result['code'] == 214) {
return json_encode(array('success' => false, 'message' => $data['Email'] . ' is already subscribed'));
} else {
return json_encode(array('success' => false, 'message' => $result['error']));
}
} else {
return json_encode(array('success' => true, 'message' => 'Thank you for subscribing to our newsletter'));
}
} else {
if (isset($result['status']) && $result['status'] == 'error') {
if ($result['code'] == 214) {
$this->sessionMessage($data['Email'] . ' is already subscribed.', 'bad');
} else {
$this->sessionMessage($result['error'], 'bad');
}
} else {
$this->sessionMessage('Thank you for subscribing to our newsletter', 'good');
}
Controller::curr()->redirectBack();
}
}
示例2: transition
public function transition($request)
{
if (!Member::currentUserID()) {
return Security::permissionFailure($this, _t('AdvancedWorkflowActionController.ACTION_ERROR', "You must be logged in"));
}
$id = $this->request->requestVar('id');
$transition = $this->request->requestVar('transition');
$instance = DataObject::get_by_id('WorkflowInstance', (int) $id);
if ($instance && $instance->canEdit()) {
$transition = DataObject::get_by_id('WorkflowTransition', (int) $transition);
if ($transition) {
if ($this->request->requestVar('comments')) {
$action = $instance->CurrentAction();
$action->Comment = $this->request->requestVar('comments');
$action->write();
}
singleton('WorkflowService')->executeTransition($instance->getTarget(), $transition->ID);
$result = array('success' => true, 'link' => $instance->getTarget()->AbsoluteLink());
if (Director::is_ajax()) {
return Convert::raw2json($result);
} else {
return $this->redirect($instance->getTarget()->Link());
}
}
}
if (Director::is_ajax()) {
$result = array('success' => false);
return Convert::raw2json($result);
} else {
$this->redirect($instance->getTarget()->Link());
}
}
示例3: validate
/**
* Overloaded so that form error messages are displayed.
*
* @see OrderFormValidator::php()
* @see Form::validate()
*/
function validate()
{
if ($this->validator) {
$errors = $this->validator->validate();
if ($errors) {
if (Director::is_ajax() && $this->validator->getJavascriptValidationHandler() == 'prototype') {
FormResponse::status_message(_t('Form.VALIDATIONFAILED', 'Validation failed'), 'bad');
foreach ($errors as $error) {
FormResponse::add(sprintf("validationError('%s', '%s', '%s');\n", Convert::raw2js($error['fieldName']), Convert::raw2js($error['message']), Convert::raw2js($error['messageType'])));
}
} else {
$data = $this->getData();
$formError = array();
if ($formMessageType = $this->MessageType()) {
$formError['message'] = $this->Message();
$formError['messageType'] = $formMessageType;
}
// Load errors into session and post back
Session::set("FormInfo.{$this->FormName()}", array('errors' => $errors, 'data' => $data, 'formError' => $formError));
}
return false;
}
}
return true;
}
示例4: include_code
public static function include_code()
{
if (Director::is_ajax()) {
self::block();
} else {
Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
Requirements::javascript('prettyphoto/javascript/jquery.prettyPhoto.js');
Requirements::css('prettyphoto/css/prettyPhoto.css');
$config = '';
$theme = Config::inst()->get("PrettyPhoto", "theme");
$moreConfigArray = Config::inst()->get("PrettyPhoto", "more_config");
foreach ($moreConfigArray as $key => $value) {
if ($value === false) {
$value = "false";
} elseif ($value === true) {
$value = "true";
} elseif ($value === intval($value)) {
//$value = $value;
} else {
$value = " '{$value}' ";
}
$moreConfigArray[$key] = "{$key}: {$value}";
}
if ($theme) {
$config .= "theme: '" . $theme . "'";
}
if ($config && count($moreConfigArray)) {
$config .= ", ";
}
if ($config) {
$config .= implode(",", $moreConfigArray);
}
Requirements::customScript('PrettyPhotoInitConfigs = {' . $config . '}; jQuery(document).ready(function(){PrettyPhotoLoader.load("' . Config::inst()->get("PrettyPhoto", "selector") . '")});', "prettyPhotoCustomScript");
}
}
示例5: submit
function submit($data, $form)
{
$member = Member::currentUser();
if (!$member || !$member->inGroup("ADMIN")) {
$form->setMessage("You need to be logged as an admin to send this email.", "bad");
return Controller::curr()->redirectBack();
}
$data = Convert::raw2sql($data);
$page = null;
if (isset($data["ModuleProductID"])) {
$page = ModuleProduct::get()->byID(intval($data["ModuleProductID"]));
}
if (!$page) {
$form->setMessage("Can not find the right page for saving this email.", "bad");
return Controller::curr()->redirectBack();
}
$email = new ModuleProductEmail();
$form->saveInto($email);
$email->write();
if (Director::is_ajax()) {
return "mail sent!";
} else {
return Controller::curr()->redirect($page->Link());
}
}
示例6: output
public function output()
{
// TODO: Refactor into a content-type option
if (\Director::is_ajax()) {
return $this->friendlyErrorMessage;
} else {
// TODO: Refactor this into CMS
if (class_exists('ErrorPage')) {
$errorFilePath = \ErrorPage::get_filepath_for_errorcode($this->statusCode, class_exists('Translatable') ? \Translatable::get_current_locale() : null);
if (file_exists($errorFilePath)) {
$content = file_get_contents($errorFilePath);
if (!headers_sent()) {
header('Content-Type: text/html');
}
// $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken
return str_replace('$BaseURL', \Director::absoluteBaseURL(), $content);
}
}
$renderer = \Debug::create_debug_view();
$output = $renderer->renderHeader();
$output .= $renderer->renderInfo("Website Error", $this->friendlyErrorMessage, $this->friendlyErrorDetail);
if (\Email::config()->admin_email) {
$mailto = \Email::obfuscate(\Email::config()->admin_email);
$output .= $renderer->renderParagraph('Contact an administrator: ' . $mailto . '');
}
$output .= $renderer->renderFooter();
return $output;
}
}
示例7: doContactFormSubmit
/**
* Handles the submission of the contact form. Checks spam and builds and sends the email
*
* @param array The form data
* @param Form The Form object
*/
public function doContactFormSubmit($data, $form)
{
Session::set("FormData.{$form->FormName()}", $data);
$proxy = $form->proxy;
foreach ($proxy->getSpamProtection() as $spam) {
if ($spam->isSpam($data, $form)) {
$form->sessionMessage($spam->getMessage(), "bad");
$spam->logSpamAttempt($this->owner->request);
return $this->owner->redirectBack();
}
}
if ($func = $proxy->getOnBeforeSend()) {
$result = $func($data, $form, $proxy);
if ($result === false) {
return $this->owner->redirectBack();
}
}
$this->sendEmail($data, $form);
Session::clear("FormData.{$form->FormName()}");
if ($func = $proxy->getOnAfterSend()) {
$func($data, $form, $proxy);
}
if ($proxy->getSuccessURL()) {
return $this->owner->redirect($proxy->getSuccessURL());
} else {
if (Director::is_ajax()) {
return new SS_HTTPResponse($proxy->getSuccessMessage());
}
$form->sessionMessage(strip_tags($proxy->getSuccessMessage()), 'good');
return $this->owner->redirectBack();
}
}
示例8: otherquestion
/**
* Skip the question via AJAX.
*/
public function otherquestion()
{
if (Director::is_ajax()) {
Session::clear('QACaptchaField.Retry');
return $this->renderWith('QACaptchaField');
}
}
示例9: index
/**
* Load an article by ajax, fallback to default rendering if not an ajax request
*
* @return string
*/
public function index()
{
if (Director::is_ajax()) {
return json_encode(array('html' => $this->renderWith("NewsItem_Content")->value));
} else {
return parent::index();
}
}
示例10: onAfterInit
/**
* Injects some custom javascript to provide instant loading of DataObject
* tables.
*
* @return void
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 13.01.2011
*/
public function onAfterInit()
{
Translatable::set_current_locale(i18n::get_locale());
if (Director::is_ajax()) {
return true;
}
Requirements::css('silvercart/admin/css/SilvercartMain.css');
}
示例11: index
function index(SS_HTTPRequest $request)
{
if (Director::is_ajax()) {
return $this->delegate($request);
} else {
return $this;
}
}
示例12: redirect
function redirect($status = "success", $message = "")
{
if (Director::is_ajax()) {
return $status;
//TODO: allow for custom return types, eg json - similar to ShoppingCart::return_data()
}
Director::redirect(CheckoutPage::find_link());
}
示例13: postRequest
public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
{
if (!$response->isError() && !Director::is_ajax()) {
// Find or create the visitor record
$visitor = Visitor::initVisitor();
// Log the arrival of this visitor to this page
$visitor->logPageArrival();
}
}
示例14: AccountPaymentFields
public function AccountPaymentFields($request)
{
if (Director::is_ajax()) {
$customer = Member::currentUser();
$fields = CompositeField::create(TextField::create('AccountPaymentNumber', 'Account Number', $customer ? $customer->AccountNumber : '')->setAttribute('required', 'required'))->setName('AccountPaymentFields');
return $fields->FieldHolder();
}
return false;
}
示例15: init
/**
*
*/
function init()
{
RSSFeed::linkToFeed(Director::baseURL() . $this->URLSegment . "/episodesRSS");
if (Director::is_ajax()) {
$this->isAjax = true;
} else {
$this->isAjax = false;
}
parent::init();
}