I have read the tutorial, and the API, looked through the code examples. But when it came down to implementation, it didn't work as i thought it would.
I am trying to avoid using the Views module for now, just for learning purposes.function mymodule_menu() {
$items['groups'] = array(
'title' => t('Groups list'),
'page callback' => 'mymodule_groups_overview',
'access callback' => TRUE
);
return $items;
}
function mymodule_groups_overview() {
$build = array();
$query = db_select('og', 'og')->extend('PagerDefault');
$query->fields('og', array('gid'));
$result = $query
->limit(10)
->orderBy('og.gid')
->execute();
if ($result) {
$gids = $result->fetchCol();
$entities = og_load_multiple($gids);
$build = entity_view('group', $entities, 'teaser');
}
return $build;
}
The problem is that entity_view(..)
returns nothing, and og_load_multiple(..)
returns an array of entities, but there is no content and no fields.
If this worked, I would probably override the controller, 开发者_运维技巧declare it in mymodule_entity_info_alter(..)
, and added a new view mode 'list'.
Can anyone please share a working code for displaying a list of entities with a pager?
P.S. I took the groups for example but i dont mind any other type of entities.
Just a thought, what happens when you use 'full' instead of teaser in the call to entity_view? Have you checked that the display mode for teasers for type 'group' actually has some fields to display in it?
精彩评论