继续Drupal分享精神 QQ群:107748121 站长QQ:2275288328 skype: hellodrupal【drupal交流+drupal 建站+theme制作】
登录 注册

Drupal arg 用法

版本
4.6 – 5
arg($index)
6 – 7
arg($index = NULL, $path = NULL)
经常会使用arg来判断url参数,但是如果没有在menu里面定义的话,使用arg得不到当前的正确url。

例如: node/7 对应的别名为 blog/7.html

<?php

print (arg(0)); //返回 node,如果不设定path,不会识别别名
print (arg(0,$_REQUEST['q']) ; // 返回 blog
print_r(arg(0,$_GET['q'])); // 返回 node
?>

例如: 如果衔接为 http://hellodrupal.info/blog

<?php

print (arg(0)); //返回 blog 直接得到
?>

代码

includes/path.inc, 159 行

<?php
function arg($index = NULL, $path = NULL) {
  static
$arguments;

  if (!isset(
$path)) {
   
$path = $_GET['q'];
  }
  if (!isset(
$arguments[$path])) {
   
$arguments[$path] = explode('/', $path);
  }
  if (!isset(
$index)) {
    return
$arguments[$path];
  }
  if (isset(
$arguments[$path][$index])) {
    return
$arguments[$path][$index];
  }
}
?>

评论

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 自动断行和分段。
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.