Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Drupal:hook\u url\u inbound\u alter in url\u rewrite:重写用于分页的url的查询部分_Drupal_Url Rewriting_Drupal 7 - Fatal编程技术网

Drupal:hook\u url\u inbound\u alter in url\u rewrite:重写用于分页的url的查询部分

Drupal:hook\u url\u inbound\u alter in url\u rewrite:重写用于分页的url的查询部分,drupal,url-rewriting,drupal-7,Drupal,Url Rewriting,Drupal 7,我正在尝试使用url_rewrite来处理分页模块的url中的非友好参数。我希望将像page title.html?page=0,1这样的URL转换为page title/page1.html 这是我的钩子: function mymod_url_outbound_alter(&$path, &$options, $original_path) { $localPath = $path . '?' . $options['query']; dpm("_url_ou

我正在尝试使用url_rewrite来处理
分页
模块的url中的非友好参数。我希望将像
page title.html?page=0,1
这样的URL转换为
page title/page1.html

这是我的钩子:

function mymod_url_outbound_alter(&$path, &$options, $original_path) {
    $localPath = $path . '?' . $options['query'];
    dpm("_url_outbound_alter($localPath)");
    if (preg_match('|(.+)\.html\?page=0%2C(\d+)|', $localPath, $matches)) {
        $path = "${matches[1]}/page${matches[2]}.html";
        unset($options['query']);
        dpm("altering path to $path");
    }
}

function mymod_url_inbound_alter(&$result, $path, $path_language) {
    if (preg_match('|(.+)/page(\d+)\.html|', $path, $matches)) {
        //$result = "${matches[1]}.html?page=0,${matches[2]}";
        $result = "${matches[1]}.html";
        //$_GET['q'] = "page=0,${matches[2]}";
        $_GET['page'] = "0,${matches[2]}";
        dpm("altering in-path to $result");
    }
}

function mymod_boot() {}
是否无法在hook\u url\u inbound\u alter中添加查询部分

  • 如果我不加评论 mymod\u url\u outbound\u alter,它可以工作, bot comma us URL编码-好的,它确实显示了友好的URL
  • 如果我同时启用这两个选项,则 页面进入无限重定向301 循环
  • 注释掉的变体也是 好像不管用
是的,我知道最好修复
分页
以使用非查询URL。但是这个模块有点太复杂了,不能可靠地做到这一点<代码>分页模块缺少适合我的功能


URL更改中存在问题吗?如何使其工作?

$options['query']
是一个包含查询参数及其值的数组,因此您必须执行以下操作

$localPath = $path . '?' . $options['query']['page']
还要注意的是,
$path
尚未被path模块重写。以下是对我有效的方法:

function pageing_url_outbound_alter(&$path, &$options, $original_path)
{
    if ($path == 'admin/content' && isset($options['query']['page']))
    {
        $path = 'admin/content/page' . $options['query']['page'];
        unset($options['query']['page']);
    }
}

function pageing_url_inbound_alter(&$path, $original_path, $path_language)
{
    if (preg_match('|admin/content/page(\d+)|', $path, $matches))
    {
        $path = 'admin/content';
        $_GET['page'] = $matches[1];
    }
}

这是给Drupal 7 RC3的

我必须说我有点困惑。您将这个问题标记为drupal-6,但hook\u url\u outbound\u alter()仅在drupal 7之后出现。另一方面,分页模块()还没有被移植到Drupal7,只对Drupal6和更早的版本可用。