简体   繁体   English

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

[英]how to display any message or data in drupal 7 .module file

how to display any message or data in mymodule.module file in drupal 7 如何在drupal 7的mymodule.module文件中显示任何消息或数据

i have used following line but it didn't display any thing 我用过以下行,但未显示任何内容

drupal_set_message(t('test message')); drupal_set_message(t('测试消息'));

aslo i want to display any variable data like for example $data = "hello" 我还想显示任何变量数据,例如$ data =“ hello”

then how to display this variable data in drupal 7 然后如何在drupal 7中显示此变量数据

i am new to drupal , so if any one knows please let me know . 我是drupal的新手,所以如果有人知道请告诉我。

i have search a lot , but didn't get anything. 我搜索了很多,但是什么也没得到。

thanks in advance. 提前致谢。


I have used folllowing code by creating module in drupal 7 我通过在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')); 

  }

In above code data is inserted in database , but message didn't displaying . 在上面的代码中,数据插入了数据库,但是没有显示消息。 If you know , what is problem please let me know , i have search a lot for this problem . 如果您知道什么是问题,请让我知道,我一直在寻找这个问题。 Thanks in advance. 提前致谢。

Here's the proper way to display some data in the message: 这是在消息中显示某些数据的正确方法:

drupal_set_message(t('test message: !data', array('!data' => $data)));

As for the message not displaying, if other messages do display on your site, it sounds like your function isn't executing. 至于未显示的消息,如果其他消息确实显示在您的站点上,则听起来您的函数未执行。 I'd need more info on what you're attempting to do (including the code involved) to debug it. 我需要有关尝试调试的更多信息(包括所涉及的代码)。

The function watchdog is also available in Drupal 7 功能看门狗在Drupal 7中也可用

Here is an exemple of how you can use it: 这是如何使用它的一个示例:

watchdog('MyModule', '<pre>'. print_r($variable, TRUE) .'</pre>', array(), WATCHDOG_INFO, NULL);

You can watch the log in Reports -> Recent log messages (admin/reports/dblog) if the core module "Database logging" is activated. 如果激活了核心模块“数据库日志记录”,则可以在“报告”->“最近的日志消息”中查看日志(admin / reports / dblog)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM