【问题标题】:Finding the file path in drupal在drupal中查找文件路径
【发布时间】:2010-07-26 12:29:02
【问题描述】:

我是 php 开发人员,我是 drupal 新手。我已经安装了一个 drupal 站点。

对于普通的 php 网站。我们可以从浏览器路径中找到文件名,进行修改 例如:

浏览器网址:www.mysite.com/test/upload.php

文件路径:test/upload.php.

drupal:http://localhost/mydreamhouse/article/557 什么是文件路径?

drupal :http://localhost/mydreamhouse/newslist 什么是文件路径?

在drupal中找到文件路径有什么通用的方法吗?或者任何人都可以描述页面的流程吗?

【问题讨论】:

    标签: php drupal


    【解决方案1】:

    Drupal URL 不必与文件相对应,它们中的大多数是根据数据库中的信息动态创建的。请参阅Understanding Drupal paths 了解更多信息。

    【讨论】:

      【解决方案2】:

      文件路径始终为 index.php(除了少数例外,如 install.php 和 cron.php)。您可以禁用 clean urls 设置以更好地了解您正在查看的路径。启用干净的 url 后,将进行一些重写以创建漂亮的 url。

      在您的情况下,http://localhost/mydreamhouse/article/557 实际上是 http://localhost/mydreamhouse/index.php?q=article/557。换句话说,调用 index.php 脚本,它会依次解释 $_GET['q'] 变量以提供正确的页面。

      【讨论】:

        【解决方案3】:
        getcwd() . base_path() . $file->filepath
        

        getcwd() - webroot的服务器路径

        base_path() - drupal 应用程序的路径(如果应用程序在 root 中,它将是 /)

        $file->filepath - 任何文件路径(例如 sites/all/default/files/...)

        【讨论】:

          【解决方案4】:

          正如其他答案所述,没有文件或页面流。 index.php 获取$_GET['q'] 的值并调用相应的函数来动态生成页面。

          您可以使用$_GET['q'] 来访问URL 的那些“文件路径”部分,但更多的Drupal 方式是使用arg(),例如,使用http://localhost/node/5 的路径,您可以访问node拨打arg(0)5 拨打arg(1)。这是访问这些 URL 部分的 Drupaly 方式。

          Drupal 还提供了用于获取基本路径的实用函数。 L 函数l() 格式化链接并为您处理基本路径(您只需编写相对链接,它会根据需要附加基本路径); base_path() 将返回同名的全局; drupal_get_path() 接受一些额外的 Drupal 特定参数,并将生成模块和主题等路径,同时考虑基本路径。

          您是否在寻找更多信息?根据这些答案细化您的问题,并查看 Drupal 的 API 文档:http://api.drupal.org/

          【讨论】:

            【解决方案5】:
            // path to Drupal dir - don't use $_SERVER['DOCUMENT_ROOT'] - drush commands will fail
            getcwd()
            
            // path to config folder - e.g. /sites/default/settings.php
            getcwd() . conf_path();  // see conf_path() for details
            
            // path to config file in module folder
            getcwd() . drupal_get_path('module','configure') . '/config.yaml'
            

            【讨论】:

              猜你喜欢
              • 2017-06-02
              • 1970-01-01
              • 1970-01-01
              • 2012-02-25
              • 2020-02-29
              • 2012-04-07
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多