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!

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

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂