如何在drupal模块中添加php文件
我有一个文件夹 /sites/main_folder/modules/file_folder/file.php
我需要在 target.module 文件中添加 file.php /sites/main_folder/modules/target_folder/target.module
。完美的代码是什么?
我在回调函数中编写了这段代码,以将 file.php 添加到我的 target.module 文件中,但什么也没发生:
$path=base_path().drupal_get_path("module","file_folder")."/";
require_once($path."file.php");
I have a folder /sites/main_folder/modules/file_folder/file.php
I need to add file.php in the target.module file/sites/main_folder/modules/target_folder/target.module
. What is the perfect code for that?
I wrote this code in my callback function to add file.php in my target.module file but nothing happened:
$path=base_path().drupal_get_path("module","file_folder")."/";
require_once($path."file.php");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是使用 Libraries API 模块。它可以帮助您将所有包含的库文件保存在一个位置(即 /sites/all/libraries/)。如果您安装并启用该模块,它将为您提供libraries_get_path() 函数。
因此,您可以将 file_folder 文件夹移动到 /sites/all/libraries/file_folder/。然后要包含该文件,您需要执行类似的操作,
确保将库添加为 .info 文件中的依赖项
One way to do this is to use the Libraries API module. It helps you to keep all of your included library files in one location (namely /sites/all/libraries/). If you install and enable that module it gives you a libraries_get_path() function.
So you could then move your file_folder folder to /sites/all/libraries/file_folder/. Then to include the file you would do something like
Be sure to add libraries as a dependency in your .info file
您只需使用 module_load_include() ,如以下示例。
You simply use module_load_include() as in the following example.