sis*_*sko 3 code-reuse drupal include-path drupal-7 drupal-modules
我使用node_clone模块效果很好但我的项目中需要使用自定义模块中的node_clone函数.所以我输入以下代码:
module_load_include('inc', 'node_clone', 'clone.pages');
function mymodule_init(){
clone_node_save(118);
}
Run Code Online (Sandbox Code Playgroud)
该代码返回Fatal error: Call to undefined function clone_node_save()
.
我的模块按来源分类为标记为mine和contrib的目录.Node_save在contrib中,而myModule在我的中.
所以,我按照以下方式修改了代码:
module_load_include('inc', '../../contrib/node_clone', 'clone.pages');
Run Code Online (Sandbox Code Playgroud)
但我得到了同样的错误.
有人能突出我做错了吗?
使用:
require_once DRUPAL_ROOT . '/sites/all/modules/contrib/node_clone/clone.pages.inc';
Run Code Online (Sandbox Code Playgroud)
不要在全局上下文中使用此函数,因为它需要完全引导Drupal,
require_once DRUPAL_ROOT . '/path/file'
而是使用它.