【问题标题】:Drupal 7 views how to modify where clause?Drupal 7视图如何修改where子句?
【发布时间】:2012-09-24 19:06:00
【问题描述】:

我有一种情况,我必须在词汇表视图的上下文过滤器中添加一个 0-9 链接

如何更改 where 子句部分? 我需要改变

SUBSTRING(node.title, 1, :node_title) = :node_title1

SUBSTRING(node.title, 1, 1) =REGEXP ('[0-9]')

如果某个值 == '0-9' 我试图实现 hook_views_query_alter 但它不起作用

function  custom_views_query_alter(&$view, &$query){

  $current_view=&$view;

  switch($current_view->name){

    case  'glossary':

  if($query->where[0]['conditions'][0]['value'][':node_title1']=='0-9'){
    $query->where[0]['conditions'][0]['field']= "SUBSTRING(node.title, 1, 1) =REGEXP ('[0-9]')";
    echo "YES";

    dpm($query->where);
        }  } }

【问题讨论】:

    标签: drupal views glossary


    【解决方案1】:

    我设法让它工作在这里的代码

    function  custom_views_query_alter(&$view, &$query){
    
    $current_view=&$view;
    switch($current_view->name){
    
    case  'glossary':
      if($query->where){
    
      if($query->where[0]['conditions'][0]['value'][':node_title1']=="0-9"){
           $query->where[0]['conditions'][0]['field'] = "SUBSTRING(node.title, 1, 1) REGEXP ('[0-9]')";
        dpm($query->where);
     }
    
    }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多