|
List Info
Thread: links
|
|
| links |

|
2007-04-23 06:44:24 |
|
Hello all,
Don't know if this is the best place for this, so if it's already discussed elsewhere, I'll be thankful if you could point me to the URL cause I couldn';t find anything myself. I'm really having a tough time when creating URLs to other parts of a Drupal site. Especially when I'm using clean URLs and even more when I have Drupal as a subfolder like
http://example.com/mydrupalsite (in which case the internal node page could be something like http://example.com/drupal/node/5)
As far as I've noticed, there are three cases of referencing, this is how I do it, but I'm positive that there's something wrong or else I wouldn';t get broken links and/or images when I toggle clean-urls on and off and when I have my site as a domain opposed to a subfolder:
1. Referencing another page, in this case I use l() or url() with relative paths to get the link 2. Referencing a file in the themes folder in which case I use src="<?php print path_to_theme().'/images/whatever.gif39;;?>
3. Referencing a file in the files folder in which case I use href="<?php print file_directory_path().'/whatever.zip9;;?>
The main headache cause is the second one. If I have clean URLs on and the site as a domain (
http://example.com/) then the paths are wrong on node pages. Although this may be a bug or something, I need to know the standard way of referencing any and all paths before I jump to conclusions. Would be grateful if someone could shed the light on this
|
| Re: links |

|
2007-04-23 06:58:15 |
|
You need to use base_path() e.g., <?php print base_path() . path_to_theme(). '/images/whatever.gif' ?>
In the first case, using l() or url() should be it, would you post an example wrong link being generated out of them?
Cheers,
On 4/23/07, Ashraf Amayreh < mistknight gmail.com">mistknight gmail.com> wrote:
Hello all,
Don't know if this is the best place for this, so if it's already discussed elsewhere, I'll be thankful if you could point me to the URL cause I couldn';t find anything myself. I'm really having a tough time when creating URLs to other parts of a Drupal site. Especially when I'm using clean URLs and even more when I have Drupal as a subfolder like
http://example.com/mydrupalsite (in which case the internal node page could be something like
http://example.com/drupal/node/5)
As far as I've noticed, there are three cases of referencing, this is how I do it, but I'm positive that there's something wrong or else I wouldn';t get broken links and/or images when I toggle clean-urls on and off and when I have my site as a domain opposed to a subfolder:
1. Referencing another page, in this case I use l() or url() with relative paths to get the link 2. Referencing a file in the themes folder in which case I use src="<?php print path_to_theme().'/images/whatever.gif39;;?>
3. Referencing a file in the files folder in which case I use href="<?php print file_directory_path().'/whatever.zip9;;?>
The main headache cause is the second one. If I have clean URLs on and the site as a domain (
http://example.com/) then the paths are wrong on node pages. Although this may be a bug or something, I need to know the standard way of referencing any and all paths before I jump to conclusions. Would be grateful if someone could shed the light on this
|
| Re: links |

|
2007-04-23 07:24:04 |
|
The l() and url() are pretty tame, I've ran through so many cases I wish I had recorded all of them, but I'll make sure to do that in the future.
Yup, base_path() did it for referencing path_to_theme() files. What about referencing files in the files directory? At a glance, all of the following seem to play a role in this. There's file_create_path() to file_create_filename() and even file_create_URL() and file_directory_path() they're simply confusing. What's the correct way to reference a file that wouldn';t become affected by clean URLs or site's URL (domain/subfolder)?
On 4/23/07, Amr Mostafa < amr.mostafa gmail.com">amr.mostafa gmail.com> wrote:
You need to use base_path() e.g., <?php print base_path() . path_to_theme(). '/images/whatever.gif' ?>
In the first case, using l() or url() should be it, would you post an example wrong link being generated out of them?
Cheers,
On 4/23/07, Ashraf Amayreh < mistknight gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
mistknight gmail.com> wrote:
Hello all,
Don't know if this is the best place for this, so if it's already discussed elsewhere, I'll be thankful if you could point me to the URL cause I couldn';t find anything myself. I'm really having a tough time when creating URLs to other parts of a Drupal site. Especially when I'm using clean URLs and even more when I have Drupal as a subfolder like
http://example.com/mydrupalsite (in which case the internal node page could be something like
http://example.com/drupal/node/5)
As far as I've noticed, there are three cases of referencing, this is how I do it, but I'm positive that there's something wrong or else I wouldn';t get broken links and/or images when I toggle clean-urls on and off and when I have my site as a domain opposed to a subfolder:
1. Referencing another page, in this case I use l() or url() with relative paths to get the link 2. Referencing a file in the themes folder in which case I use src="<?php print path_to_theme().'/images/whatever.gif39;;?>
3. Referencing a file in the files folder in which case I use href="<?php print file_directory_path().'/whatever.zip9;;?>
The main headache cause is the second one. If I have clean URLs on and the site as a domain (
http://example.com/) then the paths are wrong on node pages. Although this may be a bug or something, I need to know the standard way of referencing any and all paths before I jump to conclusions. Would be grateful if someone could shed the light on this
|
| Re: links |

|
2007-04-23 07:45:06 |
|
On 4/23/07, Ashraf Amayreh < mistknight gmail.com">mistknight gmail.com> wrote:
What about referencing files in the files directory? Sorry I forgot to answer this part.. base_path() would solve it in your example <?php print base_path(). file_directory_path() .'/whatever.zip39;; ?> but it's a wrong approach, file_create_url() is the correct function to use here as it will honor the private/public download option in the site configuration.
So a typical way to generate a download link to a file is: l(t('Download';), file_create_url($filepath)); where $filepath is the path to the file relative to the files directory.
|
[1-4]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|