跳转到主要内容
weihaol 提交于 8 September 2016

My purpose I want to render a table with 2 columns ( users' id and users' email) in views by writing a custom module. In order to alter the views, i want to change the query so that the table will be changed. Here the function that i choose is views_query_alter().

PROBLEM: The views reads my function but only return message from drupal_set_message command. And do not make any changes to Initial query and table.

Here is my function:

function my_module_views_query_alter(&$view, &$query) {
    if ($view->name == 'custom_views') {
        drupal_set_message("Hello");
        $query =db_select('users','u');
        $query -> addField('u','uid','Customer id');
        $query -> addField('u','mail','Customer Email');
        $results = $query -> execute();
    }
}

 

My purpose I want to render a table with 2 columns ( users' id and users' email) in views by writing a custom module. In order to alter the views, i want to change the query so that the table will be changed. Here the function that i choose is views_query_alter().

PROBLEM: The views reads my function but only return message from drupal_set_message command. And do not make any changes to Initial query and table.

Here is my function:

?
1 2 3 4 5 6 7 8 9 function my_module_views_query_alter(&$view, &$query) {     if ($view->name == 'custom_views') {         drupal_set_message("Hello");         $query =db_select('users','u');         $query -> addField('u','uid','Customer id');         $query -> addField('u','mail','Customer Email');         $results = $query -> execute();     } }

Here are things that i've confirmed:

1. Flush all caches. 2. my_module is enabled. 3. views has successfully read my code in my_module.views.inc because i can see the drupal_set_message command gave me a message "Hello" in the views. 4. File locations are correct.

More details about my question is on http://stackoverflow.com/questions/39379002/views-query-alter-doesnt-change-my-query-and-table-in-views

 

Thankyou for reading and i appreciate your help. :)

问题细节请点击上面我在stackoverflow 上放的问题。谢谢各位愿意帮我的朋友。

Drupal 版本