Drupal 7 开发内部培训资料, 分头诗人

请教views path结尾斜杠的问题

赞成!
0
否决!

我用views生成了一个页面,path设置为news/zt/(结尾有斜杠),提交后发现结尾的斜杠被过滤掉了,请问需要修改哪里才可以保留结尾的斜杠。 

 

2 个回答

赞成!
0
否决!

我试过drupal 6 里面hack code 好像是可以的,但drupal 7不知道,你可以试一下按照类似方法在drupal7实现。

第一步,在includes/path.inc找到下面代码,大概10~15行

/**
* Initialize the $_GET['q'] variable to the proper normal path.
*/
function drupal_init_path() {
if (!empty($_GET['q'])) {
$_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
}
else {
$_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
}
}

改为:

/**
* Initialize the $_GET['q'] variable to the proper normal path.
*/
function drupal_init_path() {
if (!empty($_GET['q'])) {
$_GET['q'] = drupal_get_normal_path($_GET['q']);
}
else {
$_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
}
}

2,安装pathauto模块,并找到sites/all/modules/pathauto/pathauto.inc,修改下面代码,大概在300行

/**
 * Clean up an URL alias.
 *
 * Performs the following alterations:
 * - Trim duplicate, leading, and trailing back-slashes.
 * - Trim duplicate, leading, and trailing separators.
 * - Shorten to a desired length and logical position based on word boundaries.
 *
 * @param $alias
 *   A string with the URL alias to clean up.
 * @return
 *   The cleaned URL alias.
 */
function pathauto_clean_alias($alias) {
  $output = $alias;
  // Trim duplicate, leading, and trailing back-slashes.
  $output = _pathauto_clean_separators($output, '/');
  // Trim duplicate, leading, and trailing separators.
  $output = _pathauto_clean_separators($output);
  // Shorten to a logical place based on word boundaries.
  $maxlength = min(variable_get('pathauto_max_length', 100), _pathauto_get_schema_alias_maxlength());
  $output = pathauto_truncate_utf8($output, $maxlength, TRUE);
  return $output;
}

改为:

/**
 * Clean up an URL alias.
 *
 * Performs the following alterations:
 * - Trim duplicate, leading, and trailing back-slashes.
 * - Trim duplicate, leading, and trailing separators.
 * - Shorten to a desired length and logical position based on word boundaries.
 *
 * @param $alias
 *   A string with the URL alias to clean up.
 * @return
 *   The cleaned URL alias.
 */
function pathauto_clean_alias($alias) {
  $output = $alias;
  // Trim duplicate, leading, and trailing back-slashes.
  // $output = _pathauto_clean_separators($output, '/');
  // Trim duplicate, leading, and trailing separators.
  $output = _pathauto_clean_separators($output);
  // Shorten to a logical place based on word boundaries.
  $maxlength = min(variable_get('pathauto_max_length', 100), _pathauto_get_schema_alias_maxlength());
  $output = pathauto_truncate_utf8($output, $maxlength, TRUE);
  return $output;
}

 

然后编写规则如:content/[title-raw]/ ,就可以了

赞成!
0
否决!

非常感谢,7的也确实在path.inc里面修改,我也修改过了,但是只对node有用,views的path不行。最终解决方案,安装Trailing Slash模块。