版本
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];
}
}
?>
评论
发表新评论