如何在Drupal7.module文件中显示任何消息或数据

如何在Drupal7.module文件中显示任何消息或数据,drupal,drupal-7,drupal-modules,Drupal,Drupal 7,Drupal Modules,如何在drupal 7中显示mymodule.module文件中的任何消息或数据 <?php function form_example_menu() { $items = array(); $items['form_example/form'] = array( 'title' => 'Example Form', //page title 'description' => 'A form to mess around

如何在drupal 7中显示mymodule.module文件中的任何消息或数据

 <?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_消息(t(“测试消息”)

我还想显示任何变量数据,例如$data=“hello”

那么如何在Drupal7中显示这个变量数据呢

 <?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的新手,所以如果有人知道,请告诉我

我找了很多,但什么也没找到

提前谢谢


我在Drupal7中创建模块时使用了以下代码

 <?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_set_message(t('test message: !data', array('!data' => $data)));

至于没有显示的消息,如果其他消息确实显示在您的站点上,则听起来您的函数没有执行。我需要更多关于调试它所尝试的操作(包括涉及的代码)的信息。

Drupal 7中也提供了函数watchdog

下面是一个如何使用它的示例:

watchdog('MyModule', '<pre>'. print_r($variable, TRUE) .'</pre>', array(), WATCHDOG_INFO, NULL);
watchdog('MyModule',''.print\r($variable,TRUE)。'',array(),watchdog\u INFO,NULL);

如果核心模块“数据库日志记录”被激活,您可以查看登录报告->最近的日志消息(admin/Reports/dblog)。

Drupal 7中也提供了函数watchdog

下面是一个如何使用它的示例:

watchdog('MyModule', '<pre>'. print_r($variable, TRUE) .'</pre>', array(), WATCHDOG_INFO, NULL);
watchdog('MyModule',''.print\r($variable,TRUE)。'',array(),watchdog\u INFO,NULL);

如果核心模块“数据库日志记录”被激活,您可以查看登录报告->最近的日志消息(admin/Reports/dblog)。

您在哪里使用这一行
drupal\u set\u消息(t(“测试消息”)?!要打印调试信息,我建议改为通过
dpm('您的价格被节省了')
打印。如果您使用了
dpm($data)
这行
drupal\u set\u消息(t('test message')),它还将以一种很好的格式为您打印变量?!要打印调试信息,我建议改为通过
dpm('您的价格被节省了')
打印。如果您使用了
dpm($data)
我还需要查看您的提交回调,那么它还会以一种很好的格式为您打印变量。此外,如果您可以发布您正在使用的确切代码,这比一个精简的示例(看起来就是这样)要好。可能有一些特定于您正在做的事情,这些事情不在上面的代码中,但可能会导致问题。此外,如果您安装了devel模块,上面的dpm()建议也是一个不错的建议(IMO,任何进行开发的人都必须这样做)。我还需要查看您的提交回调。此外,如果您可以发布您正在使用的确切代码,这比一个精简的示例(看起来就是这样)要好。可能有一些特定于您正在做的事情,这些事情不在上面的代码中,但可能会导致问题。此外,如果您安装了devel模块,那么上面的dpm()建议也是一个不错的建议(IMO,任何从事开发的人都必须这样做)。