【问题标题】:can't maintain question mark in query string无法在查询字符串中维护问号
【发布时间】:2013-02-05 08:18:08
【问题描述】:

我正在使用 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')));

URL 应以查询字符串 ?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 这样的网址。

【问题讨论】:

    标签: php url drupal


    【解决方案1】:

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

    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() 的文档

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多