从Drupal 7中的url_alias获取uid

时间:2014-01-10 21:56:33

标签: drupal

我的网址看起来像这样

http://localhost/incollect/spencer-gallery 

我想从此页面获取uid以与

进行比较
$user->uid 

帮助我能做什么我想从该节点获取uid

2 个答案:

答案 0 :(得分:1)

$acc = user_load(arg(1)); //This is based on the url path
if ($user->uid == $acc->uid){
  ...some code
}

答案 1 :(得分:0)

//Lookup system URL by alias and turn the system url into string array
$path = drupal_lookup_path('source', request_path());
$pathArr = explode("/", $path);

//Load node object if the page is of a node
if($pathArr[0] === 'node' && isset($pathArr[1])) {
$node = node_load($pathArr[1]);
//You can get any properties from the loaded node now, uncomment the line below to see it
//drupal_set_message("<pre>" . print_r($node, true) . "</pre>");
$nid = $node->nid;
$uid = $node->uid;
}