温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

drupal7 中的处理URL的三个函数

发布时间:2020-10-06 14:51:02 阅读:629 作者:ADUJ 栏目:web开发
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

我们在使用drupal7中经常使用url中的destination参数做重定性处理,drupal7中也有专门换取url上destination参数的函数,介绍如下:

drupal_get_destination();//这个函数可以获取url中的destination参数,当没有destination参数,函数会将当前url作为参数返回。

drupal_http_build_query(array $query,$parent = '');

drupal_get_query_parameters(array $query = NULL,array $exclude = array('q'),$parent = '');//默认去掉$_GET['q']部分

下面是API中代码:

function drupal_get_destination(){
    $destination = & drupal_static(__FUNCTION__);
	ifisset$destination ) ){
	    return $destination;
	}
	ifisset$_GET['destionation'] ) ){
	    $destionation array(
		    'destionation' => $_GET['destination'],	
		);
	}else{
	    $path $_GET['q'];
		$query drupal_http_build_querydrupal_get_query_parameters() );
		if$query != '' ){
		    $path .= '?'.$query;
		}
		$destination array(
		    'destination' => $path,	
		);
	}
	return $destination;
}
function drupal_http_build_query( array $query,$parent '' ){
    $params array();
	foreach$query as $key => $value ){
	    $key $parent $parent rawurlencode('['.$key.']') : rawurlencode($key);

		ifis_array$value ) ){
		    $params[] = drupal_http_build_query$value,$key );
		}else if( !isset$value ) ){
		    $params[] = $key;
		}else{
		    $param[] = $key '=' . str_replace('%2F','/',rawurlencode($value));
		}
	}
	return implode'&',$params );
}
function drupal_get_query_parameters( array $query=NULL,array $exclude array('q'),$parent '' ){
    //set default, if not given
	if( !isset$query ) ){
	    $query $_GET;
	}
    // if exclude is empty, there is nothing to filter
	ifempty$exclude ) ){
	    return $query;
	}
	elseif( !$parent ){
	    $exclude array_flip$exclude );
	}
	$params array();
	foreach$query as $key => $value ){
	    $string_key $parent $parent '[' .$key .']' : $key;
		ifisset$exclude[$string_key] ) ){
            continue;		
		}
		ifis_array$value ) ){
		    $params[$key] = drupal_get_query_parameters$value,$exclude,$string_key );
		}else{
		    $params[$key] = $value;
		}
	}
	return $params;
}

以上内容仅供参考,详细内容请参考drupal7官方网站api内容

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×