dongyang4615 2015-02-20 21:17
浏览 21
已采纳

too long

I am new to drupal coding and still fairly new to PHP. I have gotten myself to a certain point, and am now stuck! The documentation has helped me a lot up to this point, but I find myself struggling to make it over this hurdle.

My Code:

<?php

//Pulls the refering page url
$prev_page = $_SERVER['HTTP_REFERER'];

//breaks the referer into an associated array
$delimit = '/';
$splode = explode($delimit,$prev_page);

$chunked = array_slice($splode, 3, NULL);


//iterates through the array to output the address as a string
foreach($chunked as $k=>$v){
$path .=  $v."/";
}

//find the node id from the alias
$node = drupal_get_normal_path($path);
echo $node;

?>

So I have gotten the refering page address to be just the extension (ie: about-us/tim rather than http://www.google.com/about-us/tim ) to pass into drupal_get_normal_path.

I have put the actual uri into the drupal_get_normal_path and received the node information that I had expected to get, but when I use the variable as shown in the code block above it returns the text that is stored in the variable instead of finding the node source.

Any help ya'll can give is greatly appreciated!

  • 写回答

1条回答 默认 最新

  • duanfu7994 2015-02-21 19:00
    关注

    Think this is fairly similar to this question here.

    What you're doing wrong is assuming that that function returns a node - it doesn't, just returns the internal path to that node. So you still have to get the object (the node) referenced by that URL and then you actually have the node id.

    Basically, you can achieve it using (this code is slightly more efficient and compact than what you have - plus it works!):

    $url = $_SERVER['HTTP_REFERER'];
    $path = preg_replace('/\//','',parse_url($url,PHP_URL_PATH),1);
    $org_path = drupal_lookup_path("source", $path);
    $node = menu_get_object("node", 1, $org_path);
    $nid=$node->nid;
    print $nid;
    

    If you actually want to load the node, you just do node_load($nid) after all this.

    Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)