欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal l 函数 默认进行url 编码 了 怎么办 有大用

 print l('修改学校客服咨询列表',$arg0.'/'.$arg1.'/'.$arg2.'?destination=listkefu'); //这样子的话 会出现url编码的情况

应该使用 这样的形式  l('Link Text', 'path', array('query' => array('destination' => 'listkefu')));


I would like to know how I can include additional URL parameters to a given link? ie: 'news?pid=3'

<?php
print $path='news?pid=3';
?>

This returns page not found error as the '?' is getting printed as %3F.


正确答案 
 

12down voteaccepted

If you are using l(), you would do something like this to create news?pid=3.

l('Link Text', 'news', array('query' => array('pid' => '3')));

If you have other query parameters, you can add them in like this:

l('Link Text', 'news', array('query' => array('pid' => '3', 'foo' => 'bar')));

and that would create news?pid=3&foo=bar.

More information on l() here and url() here.

来自 http://drupal.stackexchange.com/questions/35476/use-url-with-query-as-url-destination




l() appends the querystring with modified ampersand symbols

The l() function modifies ampersand & Symbols in querystrings to & a m p ; This is done by the check_url function:

l() => check_url() => filter_xss_bad_protocol() => check_plain() => htmlspecialchars().

I've read about this problem, but it doesn't seem to be fixed.

Comments

pwolanin’s picture

 

Priority:Critical» Normal
Status:Active» Postponed (maintainer needs more info)

Are you passing your query in as the fourth parameter of l() ?

http://api.drupal.org/api/5/function/l

I only see $path being subjected to the treatment you describe.

kenorb’s picture

 

kenorb’s picture

 

Code:

l($text = 10, $path = 'search/all', $options = array ('path' => '/search/all', 'query' => array ('s' => 'teacher', 'items_per_page' => 10)));

Generated URI:

/search/all?s=teacher&amp;items_per_page=10
Damien Tournoud’s picture

 

Status:Postponed (maintainer needs more info)» Closed (works as designed)

This is by design.

See #399488-16: Invalid markup generated by l(). for context.

kenorb’s picture

 

Thank you.

Damien Tournoud’s picture

 

Simply decode the Output of l (link) function

$link = (t('Title'),$url, array('attributes' => array('target' => '_blank')));
$button_link = rawurldecode($link);

来自 https://www.drupal.org/node/119025


<?php
  
 $options = array(
 'attributes' => array('class' => 'fancybox btn'),
 'query' => array('popup' => TRUE)
 );
  
 print l('Download patiëntenfolders', 'overzicht-folders/'.$node->nid, $options);
  
 ?>


How will you add the query string in url using l() function?

 

If you want to use the l() function and provide the destination: 

l('Login first','user/login'array
'query' => array
'destination' => 'node/'$node->nid 


); 

?>

The above code will provide you with an anchor tag with the href pointed to user/login?destination=node/NID

This is only useful if you are linking to a page that consist of a form, and you want the user to be redirected to another page after submitting the form.

 

Ref: http://api.drupal.org/api/drupal/includes--common.inc/function/l/6 


12down voteaccepted

If you are using l(), you would do something like this to create news?pid=3.

l('Link Text', 'news', array('query' => array('pid' => '3')));

If you have other query parameters, you can add them in like this:

l('Link Text', 'news', array('query' => array('pid' => '3', 'foo' => 'bar')));

and that would create news?pid=3&foo=bar.

More information on l() here and url() here.


普通分类: