如何在 drupal 7 中显示 mymodule.module 文件中的任何消息或数据
我使用了以下行,但它没有显示任何内容
drupal_set_message(t('测试消息'));
此外,我想显示任何变量数据,例如$data = "hello"
那么如何在Drupal 7中显示这个变量数据
我是Drupal的新手,所以如果有人知道,请告诉我。
我搜索了很多,但一无所获。
提前谢谢。
我通过在drupal 7中创建模块来使用代码
<?php
function form_example_menu() {
$items = array();
$items['form_example/form'] = array(
'title' => 'Example Form', //page title
'description' => 'A form to mess around with.',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_example_form'),
'access arguments' => array('access content'), //put the name of the form here
'access callback' => TRUE
);
return $items;
}
function form_example_form($form, &$form_state) {
$form['price'] = array(
'#type' => 'textfield',
'#title' => 'What is Your Price?',
'#size' => 10,
'#maxlength' => 10,
'#required' => TRUE, //make this field required
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Click Here!'),
);
$form['form_example_form']['#submit'][] = 'form_example_form_submit';
return $form;
}
function form_example_form_validate(&$form, &$form_state) {
if (!($form_state['values']['price'] > 0)){
form_set_error('price', t('Price must be a positive number.'));
}
}
function form_example_form_submit($form, &$form_state) {
$result = db_insert('test')->fields(array('price' => $form_state['values']['price'],))->execute();
drupal_set_message(t('Your Price was saved'));
}
在上面的代码中,数据入到数据库中,但消息没有显示。 如果你知道,是什么问题请告诉我,我已经搜索了很多这个问题 .提前谢谢。
以下是在消息中显示某些数据的正确方法:
drupal_set_message(t('test message: !data', array('!data' => $data)));
至于消息没有显示,如果其他消息确实显示在您的网站上,听起来您的函数没有执行。 我需要有关您尝试执行的操作(包括所涉及的代码)来调试它的更多信息。
函数看门狗在Drupal 7中也可用
下面是如何使用它的示例:
watchdog('MyModule', '<pre>'. print_r($variable, TRUE) .'</pre>', array(), WATCHDOG_INFO, NULL);
如果激活了核心模块"数据库日志记录",您可以在报告 -> 最近的日志消息(admin/reports/dblog)中查看日志。