当前位置: 首页>>代码示例>>PHP>>正文


PHP Director::history方法代码示例

本文整理汇总了PHP中Director::history方法的典型用法代码示例。如果您正苦于以下问题:PHP Director::history方法的具体用法?PHP Director::history怎么用?PHP Director::history使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Director的用法示例。


在下文中一共展示了Director::history方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: permissionFailure

	/**
	 * Register that we've had a permission failure trying to view the given page
	 *
	 * This will redirect to a login page.
	 * If you don't provide a messageSet, a default will be used.
	 *
	 * @param Controller $controller The controller that you were on to cause the permission
	 *              failure.
	 * @param string|array $messageSet The message to show to the user. This
	 *                                  can be a string, or a map of different
	 *                                  messages for different contexts.
	 *                                  If you pass an array, you can use the
	 *                                  following keys:
	 *                                    - default: The default message
	 *                                    - logInAgain: The message to show
	 *                                                  if the user has just
	 *                                                  logged out and the
	 *                                    - alreadyLoggedIn: The message to
	 *                                                       show if the user
	 *                                                       is already logged
	 *                                                       in and lacks the
	 *                                                       permission to
	 *                                                       access the item.
	 */
	static function permissionFailure($controller = null, $messageSet = null) {
		if(Director::is_ajax()) {
			$response = ($controller) ? $controller->getResponse() : new HTTPResponse();
			$response->setStatusCode(403);
			$response->setBody('NOTLOGGEDIN:');
			return $response;
		} else {
			// Prepare the messageSet provided
			if(!$messageSet) {
				if(self::$default_message_set) {
					$messageSet = self::$default_message_set;
				} else {
					$messageSet = array(
						'default' => _t(
							'Security.NOTEPAGESECURED', 
							"That page is secured. Enter your credentials below and we will send you right along."
						),
						'alreadyLoggedIn' => _t(
							'Security.ALREADYLOGGEDIN', 
							"You don't have access to this page.  If you have another account that can access that page, you can log in below."
						),
						'logInAgain' => _t(
							'Security.LOGGEDOUT',
							"You have been logged out.  If you would like to log in again, enter your credentials below."
						)
					);
				}
			}

			if(!is_array($messageSet)) {
				$messageSet = array('default' => $messageSet);
			}

			// Work out the right message to show
			if(Member::currentUserID()) {
				$message = isset($messageSet['alreadyLoggedIn']) ? $messageSet['alreadyLoggedIn'] : $messageSet['default'];
				if($member = Member::currentUser()) {
					$member->logOut();
				}
			} else if(substr(Director::history(),0,15) == 'Security/logout') {
				$message = $messageSet['logInAgain'] ? $messageSet['logInAgain'] : $messageSet['default'];
			} else {
				$message = $messageSet['default'];
			}

			Session::set("Security.Message.message", $message);
			Session::set("Security.Message.type", 'warning');

			Session::set("BackURL", $_SERVER['REQUEST_URI']);

			// TODO AccessLogEntry needs an extension to handle permission denied errors
			// Audit logging hook
			if($controller) $controller->extend('permissionDenied', $member);

			Director::redirect("Security/login");
		}
		return;
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:82,代码来源:Security.php

示例2: permissionFailure

 /**
  * Register that we've had a permission failure trying to view the given page
  *
  * This will redirect to a login page.
  * If you don't provide a messageSet, a default will be used.
  *
  * @param Controller $controller The controller that you were on to cause the permission
  *              failure.
  * @param string|array $messageSet The message to show to the user. This
  *                                  can be a string, or a map of different
  *                                  messages for different contexts.
  *                                  If you pass an array, you can use the
  *                                  following keys:
  *                                    - default: The default message
  *                                    - logInAgain: The message to show
  *                                                  if the user has just
  *                                                  logged out and the
  *                                    - alreadyLoggedIn: The message to
  *                                                       show if the user
  *                                                       is already logged
  *                                                       in and lacks the
  *                                                       permission to
  *                                                       access the item.
  */
 static function permissionFailure($controller = null, $messageSet = null)
 {
     // Prepare the messageSet provided
     if (!$messageSet) {
         $messageSet = array('default' => _t('Security.NOTEPAGESECURED', "That page is secured. Enter your credentials below and we will send you right along."), 'alreadyLoggedIn' => _t('Security.ALREADYLOGGEDIN', "You don't have access to this page.  If you have another account that can access that page, you can log in below."), 'logInAgain' => _t('Security.LOGGEDOUT', "You have been logged out.  If you would like to log in again, enter your credentials below."));
     } else {
         if (!is_array($messageSet)) {
             $messageSet = array('default' => $messageSet);
         }
     }
     // Work out the right message to show
     if (Member::currentUserID()) {
         // user_error( 'PermFailure with member', E_USER_ERROR );
         $message = isset($messageSet['alreadyLoggedIn']) ? $messageSet['alreadyLoggedIn'] : $messageSet['default'];
         if ($member = Member::currentUser()) {
             $member->logout();
         }
     } else {
         if (substr(Director::history(), 0, 15) == 'Security/logout') {
             $message = $messageSet['logInAgain'] ? $messageSet['logInAgain'] : $messageSet['default'];
         } else {
             $message = $messageSet['default'];
         }
     }
     Session::set("Security.Message.message", $message);
     Session::set("Security.Message.type", 'warning');
     if (Director::is_ajax()) {
         die('NOTLOGGEDIN:');
     } else {
         Director::redirect("Security/login?BackURL=" . urlencode($_SERVER['REQUEST_URI']));
     }
     return;
 }
开发者ID:ramziammar,项目名称:websites,代码行数:57,代码来源:Security.php

示例3: permissionFailure

 /**
  * Register that we've had a permission failure trying to view the given page
  *
  * This will redirect to a login page.
  * If you don't provide a messageSet, a default will be used.
  *
  * @param Controller $controller The controller that you were on to cause the permission
  *              failure.
  * @param string|array $messageSet The message to show to the user. This
  *                                  can be a string, or a map of different
  *                                  messages for different contexts.
  *                                  If you pass an array, you can use the
  *                                  following keys:
  *                                    - default: The default message
  *                                    - logInAgain: The message to show
  *                                                  if the user has just
  *                                                  logged out and the
  *                                    - alreadyLoggedIn: The message to
  *                                                       show if the user
  *                                                       is already logged
  *                                                       in and lacks the
  *                                                       permission to
  *                                                       access the item.
  *
  * The alreadyLoggedIn value can contain a '%s' placeholder that will be replaced with a link
  * to log in.
  */
 static function permissionFailure($controller = null, $messageSet = null)
 {
     if (!$controller) {
         $controller = Controller::curr();
     }
     if (Director::is_ajax()) {
         $response = $controller ? $controller->getResponse() : new SS_HTTPResponse();
         $response->setStatusCode(403);
         if (!Member::currentUser()) {
             $response->setBody('NOTLOGGEDIN:');
         }
         return $response;
     } else {
         // Prepare the messageSet provided
         if (!$messageSet) {
             if (self::$default_message_set) {
                 $messageSet = self::$default_message_set;
             } else {
                 $messageSet = array('default' => _t('Security.NOTEPAGESECURED', "That page is secured. Enter your credentials below and we will send " . "you right along."), 'alreadyLoggedIn' => _t('Security.ALREADYLOGGEDIN', "You don't have access to this page.  If you have another account that " . "can access that page, you can <a href=\"%s\">log in again</a>.", PR_MEDIUM, "%s will be replaced with a link to log in."), 'logInAgain' => _t('Security.LOGGEDOUT', "You have been logged out.  If you would like to log in again, enter " . "your credentials below."));
             }
         }
         if (!is_array($messageSet)) {
             $messageSet = array('default' => $messageSet);
         }
         // Work out the right message to show
         if (Member::currentUser()) {
             $response = $controller ? $controller->getResponse() : new SS_HTTPResponse();
             $response->setStatusCode(403);
             //If 'alreadyLoggedIn' is not specified in the array, then use the default
             //which should have been specified in the lines above
             if (isset($messageSet['alreadyLoggedIn'])) {
                 $message = $messageSet['alreadyLoggedIn'];
             } else {
                 $message = $messageSet['default'];
             }
             // Replace %s with the log in link
             $body = sprintf($message, Controller::join_links(Director::baseURL(), 'Security/login', '?BackURL=' . urlencode($_SERVER['REQUEST_URI'])));
             $response->setBody($body);
             return $response;
         } else {
             if (substr(Director::history(), 0, 15) == 'Security/logout') {
                 $message = $messageSet['logInAgain'] ? $messageSet['logInAgain'] : $messageSet['default'];
             } else {
                 $message = $messageSet['default'];
             }
         }
         Session::set("Security.Message.message", $message);
         Session::set("Security.Message.type", 'warning');
         Session::set("BackURL", $_SERVER['REQUEST_URI']);
         // TODO AccessLogEntry needs an extension to handle permission denied errors
         // Audit logging hook
         if ($controller) {
             $controller->extend('permissionDenied', $member);
         }
         Director::redirect("Security/login?BackURL=" . urlencode($_SERVER['REQUEST_URI']));
     }
     return;
 }
开发者ID:NARKOZ,项目名称:silverstripe-doc-restructuring,代码行数:85,代码来源:Security.php


注:本文中的Director::history方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。