0

I am not sure if this is an issue with my current setup, or what I want to do.

I have a module that is programatically creating nodes in my Drupal 6 site, and within each I have to provide links in between various nodes.

I basically have a few foreach loops, and within each I have the current path.

For instance:

foreach ($page->category as $category) {
  $category_link = "category/" . $category['id'];

  // generate category pages
  ...
  $content = "<a href='$category_link'>".$category['name']."</a>";
  _create_node($content);

  foreach ($category->article as $article) {
    $article_link = $category_link . "/article/" . $article['id'];

    // generate article page
    $content = "<a href='$category_link'>".$category['name']."</a>";
    $content .= "<a href='$article_link'>".$article['name']."</a>";
    _create_node($content);
  }
}

The issue that I'm seeing is that the link seems to be continually built up. For instance, in the main category pages it is fine (I'll see category/1234), and the article link will be fine, but the category link will seem to be longer than it should. Basically, I'll end up seeing:

category/1234/article/5678/category/1234

My first thought was to make use of $base_url and just create absolute paths, however whenever I try printing that variable from my module it is completely empty. This is on a local server, however when I move it to production Drupal isn't installed at the root, so I can't simply add a slash to the front of the link.

4

3 回答 3

2

尝试使用$GLOBALS['base_path']获取基本路径。

于 2012-11-14T20:36:39.597 回答
1

$GLOBALS['base_path']可以,但是您正在访问一个全局变量,该变量还包含一些内容,例如您的数据库连接信息和其他一些重要内容。因此,只要手指一滑,您就可以搞砸其他事情。我更喜欢base_path()做同样的事情,但更安全一点。

于 2012-11-15T22:34:37.507 回答
0

利用

global $base_url;

对于主题文件夹的路径,请使用

path_to_theme()

您可以使用base_path(),但这不会为您提供域名。
基本网址将为您提供完整的网址,例如:www.example.com

base_path()将为您提供:/

path_to_theme()将为您提供:sites/all/themes/yourthemename

于 2013-05-09T10:15:33.180 回答