zoukankan      html  css  js  c++  java
  • [Drupal] Drupal7 How to theme a table with pager.

    As we know, Drupal7 has changed a lot, and we have to be familiar with it.

    Here is an example to theme a table with pager.

      $output = '';
      
    $header = array(
        
    array(
          
    'data'=>t('Title'),
          
    'field'=>'n.title',
        )
    ,
        
    array(
          
    'data' => '',
        )
    ,
      );

      
    $query = db_select('node', 'n')->extend('PagerDefault')->extend('TableSort');
      
    $query->fields('n', array('nid', 'title'));
      
    $ua_alias = $query->leftJoin('users_act' ,'ua', '%alias.nid = n.nid');
      
    $query->addField($ua_alias, 'uid', 'ua_uid');
      
    $query->addField($ua_alias, 'status', 'ua_status');
      
    $query->condition('n.type', 'activity');
      
    $objects = $query->limit(50)
        
    ->orderByHeader($header)
        
    ->execute()
        
    ->fetchAll();
      
    $rows = array();
      
    foreach ($objects as $key=>$object) {
        
    $row = array();
        
    $nid = $object->nid;
        
    $row[] = l(check_plain($object->title), 'node/'.$object->nid, array('attributes'=>array('target'=>'_blank')));
        
    $row[] = '<a href="?nid='.$nid.'" title='.$object->title.' target="_blank">my link</a>';
        
    $rows[] = $row;
      }
      
    $output .= theme('table', array('header'=>$header, 'rows'=>$rows, 'empty'=>t('No result found.')));
      
    $output .= theme('pager');

      return $output; 

    It is just an example, any details, please see in drupal.org

    Have fun with Drupal7! 

  • 相关阅读:
    使用Python操作MySQL数据库
    SQL server数据库语句
    SQL server数据库
    实施工程师
    Vue外卖项目
    每日思考记录(12)
    Vue核心知识点
    jQuery快速入门
    js
    css2
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/2041633.html
Copyright © 2011-2022 走看看