php - 如何在 Drupal 7 中包含 php 类

标签 php drupal drupal-7

我有这样的目录结构:

code/folder/theme/includingfile.theme.inc
code/folder/myclass.class.php

在 myclass.class.php 中,我有一个名为 DiffName 的类

我尝试过使用

module_load_include('php','DiffName','../myclass.class.php');

我也尝试过:

module_load_include('php','DiffName','../myclass.class');

在includefile.theme.inc内部,但我仍然不断收到此错误:

class DiffName could not be found in code/folder/theme/includingfile.theme.inc

要求路径必须是相对的? 你知道我做错了什么吗?

最佳答案

Drupal 有一个内置的类加载器,您需要在 .info 文件中提供包含类的文件的位置。

https://www.drupal.org/node/542202#files

就你而言,那就是

files[] = myclass.class.php

刷新缓存后(每次编辑.info文件),不需要module_load_include(),只需调用new DiffName();

关于php - 如何在 Drupal 7 中包含 php 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31946670/

相关文章:

javascript - 如何获取数据库值并将其存储在 JavaScript 变量中

php - 有人遇到过强制 PHP SimpleXMLElement 节点名称为大写的方法吗?

mysql - 找不到匹配的 SQL 类。 Drush 找不到您的数据库连接。错误

php - 使用 JavaScript 弹出窗口进行时事通讯注册的表单验证

javascript - 将 ISO 8601 时间格式化为 Laravel View

html - css 在 drupal6.20 中提供两个输出?

mysql - 为什么我无法设置我的 Kalabox Drupal 站点? SQLState[Hy000] 错误

drupal-7 - 通过脚本在 Drupal 7 中动态添加 "Field Collection"?

php - fatal error : Allowed memory size of 67108864 bytes exhausted (tried to allocate 39 bytes) in xxx/xxx/xxx/xxx

linux - Aegir:调用 hook drush_db_pre_provision_backup 后无法从 mysqldump 生成数据库备份