无法在查询字符串中维护问号

时间:2012-10-15 16:57:30

标签: php url drupal

我正在使用drupal的l()函数来构建链接。所以我将这个变量作为第二个参数传递,函数将从中生成href值。

$performer = $row->node_field_data_field_evenement_performer_title;
$url = 'node/' . $row->node_field_data_field_evenement_performer_nid . '/lightbox2';
print  l($performer, $url, array('html' => TRUE, 'attributes' => array('rel' => 'lightframe[group|width:500px; height: 500px][caption]', 'class' => 'performer-link')));

网址应以查询字符串?format=simple结尾。所以基本上我的$url变量应该更新如下:

$url = 'node/' . $row->node_field_data_field_evenement_performer_nid . '/lightbox2?format=simple';

无论我使用什么编码/解码功能,无论我做什么转义,问号和等号都会被解释为%25种类型的字符。 我试过了:

$url = 'node/' . $row->node_field_data_field_evenement_performer_nid . '/lightbox2\?format\=simple');

'/lightbox2' . any_decode_or_encode_function_outthere('?format=simple');

但我不断收到node/202/lightbox2%5C%3Fformat%5C%3Dsimple等网址。

2 个答案:

答案 0 :(得分:2)

query键用于传递给l()的选项数组:

print l($performer, $url, array(
  'html' => TRUE,
  'attributes' => array(
    'rel' => 'lightframe[group|width:500px; height: 500px][caption]',
     'class' => 'performer-link'
  ),
  'query' => array(
    'format' => 'simple'
  )
));

l()在内部调用url(),可以转发选项。请参阅url()

的文档

答案 1 :(得分:0)

尝试l($performer, $url, array('query' => array('format' => 'simple'), /*...the rest of your array...*/ );

这适用于drupal 7.在options数组中,您可以指定一个查询数组,该数组是要附加到url查询字符串的键值数组。