在 Drupal 7 中呈现查询结果的正确方法是什么?
我生成了一个查询,如下所示,并将结果格式化为链接:
$result = db_query("SELECT name FROM {taxonomy_term_data} WHERE vid = :val", array(':val' => '1'));
$list = array();
foreach ($result as $record) {
$list[] = l($record->name, 'blog/' . $record->name);
}
现在我想将此数组呈现为无序列表并将其返回到块。执行此操作的正确函数/语法是什么?
另外,与渲染相关的功能在哪里可以参考?
预先感谢您的任何帮助!
I've generated a query, as follows, and formatted the results as links:
$result = db_query("SELECT name FROM {taxonomy_term_data} WHERE vid = :val", array(':val' => '1'));
$list = array();
foreach ($result as $record) {
$list[] = l($record->name, 'blog/' . $record->name);
}
Now I would like to render this array as an unordered list and return it to a block. What's the proper function/syntax for doing this?
Also, where is a good reference for functions related to rendering?
Thanks in advance for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,“呈现查询结果的正确方法”并不存在,有很多方法。它们可以呈现为列表、表格和许多其他方式。您要求的是呈现链接列表的正确方法,这些链接来自数据库是不相关的。
请参阅http://api.drupal.org/api /drupal/includes--theme.inc/function/theme_links/7。您还可以使用所谓的可渲染数组,而不是直接调用 theme(),这是 Drupal 7 中的一项新功能,也是现在执行此操作的首选方法。
Note that "the proper way to render a query result" does not exist, there are many ways. They could be rendered as a list, as a table and many other ways. What you are asking for is the proper way to render a list of links, that these links are coming from the database is not relevant.
See http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_links/7. And instead of calling theme() directly, you can also use the so called renderable arrays which are a new feature in Drupal 7 and the preferred way to do this now.
这是一种方法。构建
$vars
数组并将其传递给theme_item_list($vars)
:http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_item_list/7
Here's one way to do it. Build
$vars
array and pass it totheme_item_list($vars)
:http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_item_list/7