您的位置:首页 > 其它

[Drupal] Drupal7 - How to theme a table with pager.

2011-05-09 22:14 441 查看
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!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐