我有这样的目录结构:
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/