如何在drupal hook_block中打印输出
如何打印输出,如果我在函数中用 WHILE SNIPPET 编写,
下面是我的代码片段,我想打印检索到的结果,
我尝试了 echo ,
但我们不应该在 drupal 中使用 echo ,并且 drupal 设置消息函数用于调试目的,
所以如何打印本例中的输出,
function node_example_block($op='list',$delta=0){
switch($op){
case "list":
$block[0]['info'] = t('THIS IS EXAMPLE NODE EXAMPLE ');
return $block;
case "view":
$block['subject'] = "THIS MY FIRST SAMPLE BLOCK";
$block['content'] = drupal_get_form('display_node_title');
return $block;
}
}
function display_node_title(){
$result = db_query("SELECT * FROM node");
$output = '';
while ($obj = db_fetch_object ($result)){
$output .= $obj->title;
}
//drupal_set_message($output);
}
How to Print the output, if i written in WHILE SNIPPET in the function ,
Below is my snippet, i want print retrieved result ,
i tried echo ,
but we should not use echo in drupal, and drupal set message function for debug purpose ,
So how to print my output in this example ,
function node_example_block($op='list',$delta=0){
switch($op){
case "list":
$block[0]['info'] = t('THIS IS EXAMPLE NODE EXAMPLE ');
return $block;
case "view":
$block['subject'] = "THIS MY FIRST SAMPLE BLOCK";
$block['content'] = drupal_get_form('display_node_title');
return $block;
}
}
function display_node_title(){
$result = db_query("SELECT * FROM node");
$output = '';
while ($obj = db_fetch_object ($result)){
$output .= $obj->title;
}
//drupal_set_message($output);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已通过
drupal_get_form
传递display_node_title
,但display_node_title
不是表单函数。如果是的话,它将通过 Form API 构造一个$form
数组,并在最后return $form;
。将: 更改
为:
并将: 添加
到
display_node_title()
函数的末尾。You're having
display_node_title
get passed throughdrupal_get_form
, butdisplay_node_title
isn't a form function. If it were, it'd be constructing a$form
array via the Form API andreturn $form;
at the end.Change:
to:
and add:
to the end of your
display_node_title()
function.