Hi, all.

I have a quick question for anyone that can help:

I came across the l() function the other day, and came to realize I should be using it in my code to generate my links.

I wrote the following link before I found this function:

<a href="/'.$_SERVER["REQUEST_URI"].'&CompletedID='.$row->TaskID . '><img src="/misc/img/b_drop.png" Title="Mark Complete" name="CompletedID" border=0></a>

Its basically an image that you click on to mark a "task" complete. It calls the current page, with a CompletedID attribute in the URL.

How to I get the path for my current page in order to use this function?
This doesn't work:
l('Image Here', $_SERVER["REQUEST_URI"], array(), "CompletedID=$row->TaskID")

This does work (but its a hack & wont work if clean URLs is on):
l('Image Here', $_GET["q"], array(), "CompletedID=$row->TaskID")

Any help would be appreciated.

Thanks,
-Ben

Comments

This does work (but its a hack & wont work if clean URLs is on):
l('Image Here', $_GET["q"], array(), "CompletedID=$row->TaskID")

That looks like it should work to me.
What does it get wrong? What does the resulting link look like?

.dan.

http://www.coders.co.nz/

drupal_get_destination() returns the current path if you call it without parameters. It uses:

$destination[] = $_GET['q'];

demolicious | leafish

I was under the impresion that with clean url's on the 'q' attribute is gone from the URL.

i.e.
www.example.com/?q=MyPath/here
would be:
www.example.com/MyPath/here

would of thought that that meant that using $_GET['q'] would return null, since there is now no q variable in the URL?

I don't have clean URLs on (and can't turn them right now to test it). I'm gonna assume this solution works, since it is in the drupal core. Anyone know for sure? If so, how does it work?

Thanks so much for the help.

clean_urls hides the 'q' but Drupal still uses it internally.

Technically, Apache mod_rewrite accepts the clean version, then inserts the ?q= before passing the request to Drupal.

As far as PHP is concerned, it's there in the $_GET all along.

.dan.

http://www.coders.co.nz/

I've been searching for over an hour all over Drupal core modules ! Thank you !

$_GET["q"] may not work for multi-language website , the following code will work in multi-language environment

<?php
$current_path
= explode('=', drupal_get_destination());
 
// Extracting URL from $current_path
 
if(is_array($current_path) && count($current_path) >= 2) {
    if(
trim($current_path[1]) != ''){
     
$current_url_full = htmlspecialchars( urldecode($current_path[1]) );
     
// Removing query string
     
$current_url_elements = explode('?', $current_url_full);
      if(
is_array($current_url_elements)) {
        return
trim($current_url_elements[0]);
      }
      else{
        return
trim($current_url_elements);
      }
    }
    else {
      return
$_REQUEST['q'];
    }
  }
?>

Dhanesh H
Drupal Developer
http://2basetechnologies.com/

Surprised there isn't a global for this

OpenTactics | Marketing and Development