Drupal 6 node_view 空
我正在尝试生成一个包含特定节点列表的页面,但 node_view 返回一个空字符串。
这是我的查询:
function events_upcoming() {
$output = '';
$has_events = false;
$res = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'events' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10));
while ($n = db_fetch_object($res)) {
$output .= node_view(node_load($n->nid), 1);
$has_events = true;
}
if ($has_events) {
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
}
return $output;
}
hook_menu(部分):
'events/upcoming' => array(
'title' => t('Upcoming Events'),
'page callback' => 'events_upcoming',
'access arguments' => array('access content'),
'type' => MENU_SUGGESTED_ITEM
),
hook_view 的实现:
function events_view($node, $teaser = false, $page = false) {
$node = node_prepare($node, $teaser);
if ($page) {
// TODO: Handle breadcrump
}
return $node;
}
现在,如果我在 events_view 内添加 var_dump($node) ,则节点存在,我可以看到我想要的值,如果我在 while 内添加 var_dump在 events_upcoming 中循环我还从查询中获取了一个节点 id。
奇怪的是,当我加载 localhost/events/upcoming 时,我看到了寻呼机,但什么也没有。
我已使用 blog.module 作为参考,但我在这里缺少什么?
I'm trying to produce a page with a list of specific nodes but the node_view returns an empty string.
This is my query:
function events_upcoming() {
$output = '';
$has_events = false;
$res = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'events' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10));
while ($n = db_fetch_object($res)) {
$output .= node_view(node_load($n->nid), 1);
$has_events = true;
}
if ($has_events) {
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
}
return $output;
}
hook_menu (part of):
'events/upcoming' => array(
'title' => t('Upcoming Events'),
'page callback' => 'events_upcoming',
'access arguments' => array('access content'),
'type' => MENU_SUGGESTED_ITEM
),
the implementation of hook_view:
function events_view($node, $teaser = false, $page = false) {
$node = node_prepare($node, $teaser);
if ($page) {
// TODO: Handle breadcrump
}
return $node;
}
now, if I add a var_dump($node) inside events_view the node is present and I can see the values I want, and if I add a var_dump inside while loop in events_upcoming I also get a node id from the query.
the strange thing is, when I load localhost/events/upcoming I see the pager and nothing else.
I have used the blog.module as a reference, but what am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是线程,其中有一个补丁,还有我的另一个答案。
http://drupal.org/node/229411
你可以在你想要做的每个地方使用node_load node_view,但这似乎浪费了你的处理器。
检查补丁,尽管它位于核心节点模块上。
Here the thread, with a patch in it, and another answer as well from me.
http://drupal.org/node/229411
You can use node_load at each spot you want to do the node_view, but that seems wasteful of your processor.
Checkout the patch, though it's on the core node module.