【发布时间】:2021-04-01 03:37:53
【问题描述】:
我有一个 drupal 8 选择查询,它返回项目列表,我想给它添加分页,但是分页器进入节点但它没有正确分页它显示所有结果,这是我的代码
$sql = "SELECT nid FROM node WHERE type='used_item'";
$item_nids= \Drupal::database()->query($sql)
->fetchAllAssoc('nid');
$total=count($item_nids);
$num_per_page='12';
$pager = \Drupal::service('pager.manager')
->createPager($total, $num_per_page);
$page = $pager
->getCurrentPage();
// Load the item nodes from the list array.
$item_nodes = Node::loadMultiple(array_keys($item_nids));
// Build the items.
$item_build = \Drupal::entityTypeManager()->getViewBuilder('node')-
>viewMultiple($item_nodes, 'carousel_card');
$build[] = [
'#theme' => 'full_list',
'#name' => $name,
'#description' => $description,
'#item_cards' => $item_build,
];
$build[] = [
'#type' => 'pager',
];
return $build;
如果我做错了什么,请告诉我。
【问题讨论】:
标签: php pagination drupal-8