欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal views pager ajax 分页 ajax

shiping1 的头像

1)禁用所有开发模块 特别是 devel themer模块
2)在views的block(区块)或者(页面)中使用 分页 和 ajax   
3)清缓 cron 等步骤
3)如果在程序中出现超越 过滤器的方法
就要在 sites/all/modules/views/includes/ajax.inc
大约40行如下的代码 (不是要完全一样 反正是在这里超越)
//这个是自己改写超越的ajax开始
            if ($view->name == 'bijibyjiaocheng' && ($display_id == 'block_1' || $display_id == 'block_2')) {
                $viewPath=$_GET['view_path'];
                $viewPathArr = explode('/',$viewPath);
                $arg1= $viewPathArr[1];
                $jiaoChengId = db_result(db_query("select nid from {content_type_jiaocheng} where field_jiaochengshipingobj_nid=%d",$arg1));
                $filters = $view->display_handler->get_option('filters');
                $filters['nid']['value']['value']=$jiaoChengId;
                $view->display_handler->override_option('filters', $filters);
            }
            
            if ($view->name == 'tiwenbyjiaocheng' && ($display_id == 'block_1' || $display_id == 'block_2'))
            {
                $viewPath=$_GET['view_path'];
                $viewPathArr = explode('/',$viewPath);
                $arg1= $viewPathArr[1];
                $jiaoChengId = db_result(db_query("select nid from {content_type_jiaocheng} where field_jiaochengshipingobj_nid=%d",$arg1));
                $filters = $view->display_handler->get_option('filters');
                $filters['nid']['value']['value'] = $jiaoChengId;
                $view->display_handler->override_option('filters', $filters);
            }          
              //这个是自己改写超越的ajax结束

4)还要hook_views_query_alter 见下面的例子

function taxonomy_location_views_query_alter(&$view, &$query) {
  $tid = subdomain_get_sid(subdomain_get_current_subdomain());
  if($tid) {
    $query->where[0]['clauses'][] = "(node.vid IN (SELECT tn.vid FROM term_node tn WHERE tn.tid = %d))";
    $query->where[0]['args'][] = $tid;
  }
} 此例来自 http://drupal.stackexchange.com/questions/15378/alter-views-with-hook-views-query-alter  

//我的代码如下
//这个是对ajax查询的修改
function shipingzhongcustomtwo_views_query_alter(&$view, &$query)
{
    if ($view->name == 'bijibyjiaocheng') {
        $filters = $view->display_handler->get_option('filters');
        $query->where[0]['args'][0] = $filters['nid']['value']['value'];
    }
    if ($view->name == 'tiwenbyjiaocheng'){
        $filters = $view->display_handler->get_option('filters');
        $query->where[0]['args'][0] = $filters['nid']['value']['value'];
    }
    
}

普通分类: