本文整理汇总了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;
}
示例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;
}
示例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;
}