Drupal 6:使自定义功能可用于不同模块
我有几个自定义 PHP 函数,我希望将它们提供给我创建的多个模块。
解决这个问题的 drupal 正确方法是什么?基本上,我想避免在我拥有的每个模块中复制所有这些函数。
I have a couple of custom PHP functions that I would like to make available to several modules I created.
What would be the drupal-correct way to get around this problem? Basically, I would like to avoid copying all those functions inside every module I have.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,你不能只是将函数复制到每个模块中,因为如果你有两个或多个带有这些函数的模块,那么你会得到关于已经声明的函数的 PHP 错误(除非你在每个模块中都努力重命名它们)模块)。
最好的方法取决于您的具体使用情况,但假设它们是相关核心或 api 功能的集合,那么我会将它们放入一个单独的模块中,然后任何其他模块都可以将核心模块作为依赖项。
Well, you can't just copy the functions into every module because if you have two or more modules with those functions then you'll get PHP errors about the function already having been declared (unless you go through the effort of renaming them in each module).
The best way to go about it depends on your exact usage, but assuming they are a collection of related core or api functionality, then I would place these into a separate module and then any additional modules could have the core module as a dependency.