drupal7 中的处理URL的三个函数
admin
2023-06-15 13:02:59
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__);
	if( isset( $destination ) ){
	    return $destination;
	}
	if( isset( $_GET['destionation'] ) ){
	    $destionation = array(
		    'destionation' => $_GET['destination'],	
		);
	}else{
	    $path = $_GET['q'];
		$query = drupal_http_build_query( drupal_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);

		if( is_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
	if( empty( $exclude ) ){
	    return $query;
	}
	elseif( !$parent ){
	    $exclude = array_flip( $exclude );
	}
	$params = array();
	foreach( $query as $key => $value ){
	    $string_key = $parent ? $parent . '[' .$key .']' : $key;
		if( isset( $exclude[$string_key] ) ){
            continue;		
		}
		if( is_array( $value ) ){
		    $params[$key] = drupal_get_query_parameters( $value,$exclude,$string_key );
		}else{
		    $params[$key] = $value;
		}
	}
	return $params;
}

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

相关内容

热门资讯

伊朗伊斯兰革命卫队:过去24小... △霍尔木兹海峡(资料图)当地时间26日晚间,伊朗伊斯兰革命卫队海军公共关系部发布消息称,过去24小时...
AI公司烧不起Token了!国... 新智元报道 【新智元导读】4个月烧光全年AI预算,天价Token账单正在屠杀硅谷!今天,高性能Ag...
消息称AMD苏姿丰布局Zen ... 来源:市场资讯 (来源:IT之家) IT之家 5 月 26 日消息,工商时报昨日(5 月 25 日)...
伊朗总统:毫不动摇捍卫领土与国... 当地时间5月26日,伊朗总统佩泽希齐扬发表讲话时表示,伊朗向伊斯兰国家伸出了“兄弟般的友谊之手”。与...
气象科普课堂搬进学校,高要首个... 近日,高要区气象局与高要区第一中学完成校园气象站共建并开展首场气象科普培训,将气象科普课堂搬进学校,...
2026年济南科技活动周正式启... 5月26日上午,2026年济南科技活动周启动仪式暨全国科技工作者日(槐荫)主场活动在山东科技会堂隆重...
凤凰晚报丨投毒杀人者、 三体公... 今日人物【风暴眼丨中国版“绝命毒师”伏法!揭秘三体原CEO许垚投毒轨迹】“三体公司”原CEO许垚,被...
大润发创始人尹衍樑逝世,享年7... 5月26日,润泰集团证实,润泰集团总裁、唐奖创办人、大润发创始人尹衍樑,于2026年5月26日凌晨4...
全国科技工作者日 |市科协搭台... 科技创新是很多中小企业的“短板”,为帮助企业解决技术难题,5月20日,泰州市科协组织“工博士”科技服...
LLC磁集成变压器厂家梳理 新... 导语:LLC磁集成变压器作为高频变压器领域的技术分支,凭借高功率密度、低损耗等特性,成为新能源、工业...