Get path

sami_k - March 4, 2006 - 04:24
Project:Node Image Block
Version:HEAD
Component:Code
Category:bug report
Priority:normal
Assigned:budda
Status:closed
Description

Good module! I would suggest that you the following function to get the nid because the method you're using would be problematic if the node is aliased. I would suggest that you just have it as a local function. I think something similar needs to be in the core...

<?php
function getnid(){
   
$path = drupal_lookup_path('source', $_GET['q']);
    if(
$path == false){
       
$path = $_GET['q'];
    }
   
$pathvars = explode('/', $path);
    if (
$pathvars[0] == 'node'){
       
$nid = $pathvars[1];
    }
    return
$nid;   
}
?>

#1

budda - March 6, 2006 - 18:20
Assigned to:Anonymous» budda
Status:active» fixed

Thanks - have added your function to CVS / 4.7.0.

#2

sami_k - March 13, 2006 - 02:25
Status:fixed» closed

since you committed it, i am going to close this.. thanks!

#3

tenrapid - March 18, 2006 - 20:04
Status:closed» won't fix

This is unnecessary.

During bootstrap $_GET['q'] gets set to the system path and does not contain an aliased path anymore.

So the good old if(arg(0) == 'node') { $nid = arg(1); ... is the way to go.

#4

tenrapid - March 18, 2006 - 20:07
Status:won't fix» active

#5

sami_k - March 19, 2006 - 14:25

thanks for the clarification.

#6

sami_k - March 19, 2006 - 14:40

i have checked, and this is in fact the case! so do revert the code back as tenrapid suggests... sorry about that.

#7

budda - March 20, 2006 - 11:41
Version:4.7.x-1.x-dev» HEAD
Status:active» fixed

Reverted back to original code.

#8

Anonymous - April 3, 2006 - 11:45
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.