Drupal主题函数没有被调用?
我是 Drupal 的新手,正在尝试创建一个主题功能,为我的视频创建一个小 iframe。我正在菜单回调函数中调用该函数。问题是主题函数没有被调用。我尝试在主题函数的开头附加模块名称,也将其删除,但没有帮助。每次进行更改并在开发模块中启用回溯时,我都会清除缓存,并看到以下警告:
警告:call_user_func_array() 期望参数 1 是有效的 回调,函数“mymodule_mobile_mymdue_mobile_build_iframe”不是 在 call_user_func_array() 中找到或无效的函数名称(第 656 行) /var/www/includes/theme.inc)。 =>
function my_callback_function(){
$output = theme('mymodule_mobile_build_iframe',array(
'arg1'=> $stream,
'arg2'=> $node->nid,)
);
return $output
}
function mymodule_mobile_theme(){
return array(
'mymodule_mobile_build_iframe' => array(
'arguments' => array(
'arg1' => NULL,
'arg2' => NULL,),),);
}
function theme_mymodule_mobile_build_iframe($arg1,$arg2){
$host = 'http://www.myhost.com';
$output = '<video width="320" height="240" controls="controls"> <source src=
"'.$host.'/'.$arg1.'/'.$arg2.'/playlist.m3u8" type="video/mp4" />
Your browser does not support the video tag.
</video>';
return $output;
}
提前谢谢大家!
I am new to Drupal and trying to create a theme function that create a little iframe for my videos. I am calling the function in my menu callback function. The problem is that the theme function is not called. I tried to append the module name at the beginning of the theme function and also removed and it didn't help. I clear the cache every time I make changes and enabled the backtrace in my devel module and I see the following warning:
warning: call_user_func_array() expects parameter 1 to be a valid
callback, function 'mymodule_mobile_mymodue_mobile_build_iframe' not
found or invalid function name in call_user_func_array() (line 656 of
/var/www/includes/theme.inc). =>
function my_callback_function(){
$output = theme('mymodule_mobile_build_iframe',array(
'arg1'=> $stream,
'arg2'=> $node->nid,)
);
return $output
}
function mymodule_mobile_theme(){
return array(
'mymodule_mobile_build_iframe' => array(
'arguments' => array(
'arg1' => NULL,
'arg2' => NULL,),),);
}
function theme_mymodule_mobile_build_iframe($arg1,$arg2){
$host = 'http://www.myhost.com';
$output = '<video width="320" height="240" controls="controls"> <source src=
"'.$host.'/'.$arg1.'/'.$arg2.'/playlist.m3u8" type="video/mp4" />
Your browser does not support the video tag.
</video>';
return $output;
}
Thank you all in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑这是一个简单的命名问题;您的模块名为
mymodule
或mymodule_mobile
吗?这将与模块的.info
文件同名(显然减去.info
)。如果它的名称为
mymodule
,那么您只需将主题挂钩更改为mymodule_theme()
。所有 Drupal 挂钩都是 MODULENAME_HOOKNAME(),如果您的模块名为mymodule
,Drupal 将期望寻找名为mymodule_theme()
的主题挂钩函数。最简单的测试是将
drupal_set_message('test');
行作为主题挂钩函数的第一行并清除缓存。如果您没有看到test
消息输出到屏幕上,则说明您的挂钩函数尚未运行,并且未正确命名。如果您确实看到
test
消息,但它仍然不起作用,我建议它表明其他地方存在问题,您的代码的其余部分看起来很正常。编辑
我刚刚在评论中注意到您正在使用模板文件...我认为这样做存在一些混乱,因此您需要在从
hook_theme 返回的数组中包含
。你能澄清一下吗?template
键()I would suspect this is a simple naming problem; is your module called
mymodule
ormymodule_mobile
? This will be the same name as your module's.info
file (obviously minus the.info
).If it's called
mymodule
then you just need to change your theme hook to be namedmymodule_theme()
. All Drupal hooks are MODULENAME_HOOKNAME(), if your module is calledmymodule
Drupal will be expecting to look for a theme hook function calledmymodule_theme()
.The simplest test is to put the line
drupal_set_message('test');
as the first line of your theme hook function and clear your caches. If you don't see thetest
message output to the screen, your hook function hasn't run, and it isn't named correctly.If you do see the
test
message and it still doesn't work I'd suggest it indicates a problem somewhere else, the rest of your code looks spot on.EDIT
I just noticed in a comment you're using a template file...I think there's some confusion as to do so you'd need to have the
template
key in the array returned fromhook_theme()
. Could you just clarify that?我在你的代码中没有看到任何问题(我没有测试它),但是你确定你已经清除了缓存...请清除缓存并告诉我这个问题是否仍然存在
i don't see any problem in ur code (i didn't test it) , but are you sure you have cleared the cache...please clear the cache and tell me if this problem is still exist