使用模块:url_alter 和它的钩子:hook_url_outbound_alter() [英] Using module: url_alter and it's hook: hook_url_outbound_alter()

查看:32
本文介绍了使用模块:url_alter 和它的钩子:hook_url_outbound_alter()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hook_url_outbound_alter()

我正在努力寻找有关如何使用此钩子的任何文档或解释.我有一个页面:node/1221,当它看起来像这样时:node/1221/profile/chn/3 它加载了该用户的配置文件.

I am struggling to find any documentation or explanation for how to use this hook. I have a page: node/1221 and when it look like so: node/1221/profile/chn/3 It loads a profile for that user.

我想要漂亮的 URL 以便当用户访问 departments/pch/chn/profile/3 我希望它实际加载 node/1221/profile/chn/3

I want pretty URL's so that when the user visits departments/pch/chn/profile/3 I want it to actually load node/1221/profile/chn/3

我很确定钩子应该可以帮助我解决这个问题,但不确定它是如何工作的.

I am pretty sure the hook should help me with this but not sure how it works.

注意:使用 drupal 6,尝试使用别名,但没有奏效.

第二次更新:
URL 中的 3 是我想传递给另一个 URL 的配置文件 ID.我有 node/1221/profile/chn/3 工作,因为它有一个面板,可以获取 %4 参数并将其传递给面板内的视图.希望这能提供更多背景信息.

2nd update:
The 3 in the URL is a profile ID that I want to pass on to another URL. I have node/1221/profile/chn/3 working because it has a panel that grabs the %4 argument and passes it to a view inside the panel. Hope this gives more context.

目前正在尝试:

/**
 * Implementation of hook_boot()
 */
function pathargs_boot() {
  // remain empty, only needed to let Drupal bootstrap system know to load this module earlier.
}

/**
 * Will define custom_url_rewrite_inbound(). If url_alter is enabled 
 * Pathargs inbound alter will be called by its implementation of 
 * custom_url_rewrite_inbound() instead.
 */
if (!function_exists('custom_url_rewrite_inbound')) {
  function custom_url_rewrite_inbound(&$result, $path, $path_language) {
    return pathargs_url_inbound_alter($result, $path, $path_language);
  }
}

/**
 * Implementation of hook_url_inbound_alter()
 */
function pathargs_url_inbound_alter(&$result, $path, $path_language) {
  watchdog('Path Arguments', "$path + $original_path");
  if($result == 'chn') {
    $result = 'node/1222/chn/profile/3';
  }
}

仍然无法正常工作...访问 www.domain.com/chn 没有任何作用.

Still not working... visiting www.domain.com/chn does nothing.

推荐答案

试试这个:http://drupal.org/project/subpath_alias 根据该模块的描述,它会做你想做的事.

Try this: http://drupal.org/project/subpath_alias According to that module's description it does what you want it to do.

这篇关于使用模块:url_alter 和它的钩子:hook_url_outbound_alter()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆