Drupal 7查看如何修改where子句?

时间:2012-09-24 19:06:00

标签: drupal views glossary

我有一种情况,我必须在词汇表视图的上下文过滤器中添加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);
        }  } }

1 个答案:

答案 0 :(得分:0)

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

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);
 }

}
}
}