Php 访问node/1和以编程方式加载它时的渲染差异
节点加载用户的配置文件(外部数据库+视图)。当我访问node/123/profile/id/3时,所有这些都可以工作。现在我已经实现了hook_menu(),以便加载任何配置文件页面并获得更好的URL 当我出于某种原因自己加载它时,page.tpl.php中的$left突然变为空,许多变量似乎没有加载。我尝试了许多不同的函数来渲染和创建正确的$output,但意识到node_show()似乎是首选函数 测试表明,由于某些原因,Php 访问node/1和以编程方式加载它时的渲染差异,php,drupal,drupal-6,Php,Drupal,Drupal 6,节点加载用户的配置文件(外部数据库+视图)。当我访问node/123/profile/id/3时,所有这些都可以工作。现在我已经实现了hook_menu(),以便加载任何配置文件页面并获得更好的URL 当我出于某种原因自己加载它时,page.tpl.php中的$left突然变为空,许多变量似乎没有加载。我尝试了许多不同的函数来渲染和创建正确的$output,但意识到node_show()似乎是首选函数 测试表明,由于某些原因,hook\u nodeapi()调用被忽略。 我的代码: 那么,正确的
hook\u nodeapi()
调用被忽略。我的代码: 那么,正确的方法是什么,以使面板(见下面的评论)正确加载 更新: 我正在使用和视图2连接到另一个数据库,其中包含有关非系统用户的信息。这是一个校友页面,该页面由外部管理,内部显示(我无能为力,必须让它工作:)
刚发现面板根本没有加载。因此,即使我尝试加载的节点出于某种原因使用了面板,也不会加载任何面板。渲染节点加载的结果与转到stock Drupal路径/节点不同的原因有很多。老实说,这太过分了,但简单的回答是,您必须为创建的每个页面定义模板/主题和块等。仅仅因为您创建了一个新路径并在该路径的回调中加载了一个节点,并不意味着Drupal可以自动知道您希望如何显示该内容。它只是从节点加载数据,然后就可以随心所欲地使用它。这就是为什么您会看到一个空白的页面,而不是通过/node所期望的页面
/**
* Menu path wildcard callback
*/
function website_profile_load($uid = null) {
if (!$uid) {
global $user; // if no user passed in argument, show current user profile
$uid = $user->uid;
}
$output = drupal_render(content_profile_show_profiles($uid));
}
不过,我将提供这个简单的解决方案,因为听起来您想要的页面与您转到“node/123/profile/id/3”时得到的页面完全相同,但可以通过您自己定义的链接访问。您只需在hook_菜单中设置重定向,如下所示:
$items['my/nice/url/profile'] = array(
'description' => 'This page holds a view that shows profiles based on the %',
'page callback' => 'drupal_goto',
'page arguments' => 'node/123/profile/id/3',
'access callback' => TRUE,
'type' => MENU_CALLBACK);
这本质上是说,当您导航到“my/nicer/url/profile”时,它会运行:drupal_goto('node/123/profile/id/3') 我发现答案显然是,在创建节点的过程中,Drupal使用
$$path
(最初由$\u GET['q']
设置)有时还使用$\u GET['q']
来确定如何呈现页面。请注意,我正在使用面板和Ctools页面管理器模块,以便使我的东西正常工作
结果是,如果你搜索代码,你会在$\u GET['q']
中查找大量的内容
以下是我的结论:
/**
* Implementation of hook_menu
*/
function modulename_menu() {
$items = array();
// For department and having nice URL's for their profile pages.
$items['my/nice/url/profile/%'] = array(
'description' => 'This page holds a view that shows profiles based on the %',
'page callback' => 'website_profile_load',
'page arguments' => arg(4),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Menu path callback
*/
function website_profile_load($id = NULL) {
// Rename the query internally since other functions base the design
// on the way the query is structured and not simply by the node which
// is currently loading.
if(!empty($id)) {
$path = $_GET['q'] = 'node/1221/profile/id/' . $id;
}
// Use ctools function to correctly display node view since
// this site heavily uses ctools rendering for panels and
// web parts / web pages.
drupal_load('module', 'page_manager');
ctools_include('node_view', 'page_manager', 'plugins/tasks');
if(function_exists('page_manager_node_view')) {
$output = page_manager_node_view(node_load(1221));
} else {
// Will display incorrectly but still load the UI
$output = node_page_view(node_load(1221));
}
return $output;
}
而且它是有效的:)这假设站点是使用我快速浏览了一下这个模块,发现它很有趣,但我不知道你是如何得到这个解决方案的。你能再解释一下吗!?事实上,我没有使用content_profile:),但猜测并不遥远。我已经用细节更新了上面的问题。嗨,马特,谢谢你的回答,我现在就试试。实际上,我正试图了解更多关于drupal如何呈现页面的信息,并对node_load()和theme()有一个很好的把握。正如我在Drupal Pro开发书中所理解的那样,node_page_view()实际上是我想要调用它的方式。只是,这没什么区别。我尝试过主题()节点\加载()和节点\页面\视图()。它们都不符合描述。好吧,我现在意识到,我担心,这不是答案,因为它执行HTTP重定向,并且不维护好的URL。这对这个平台非常重要。嗯,是的,我在发布后意识到这会改变导航栏中的URL。在重定向之后,您可以始终使用JavaScript将导航栏中的内容更改为您想要的任何内容,但这是一个非常糟糕的解决方案。下面是我的建议,进入core node.module并查找function node_菜单。然后尝试找出哪些路径对应于您的目标(node/123/profile/id/3),然后基本上将页面回调等复制到模块的hook_菜单中。如果你想揭开内核的神秘面纱,你可以随时检查Drupal的股票代码!作为记录:我认为您不需要页面管理器,这里的要点只是将查询设置为您的nid。所以您只需要两行:$\u GET['q']='node/1221/profile/id/'$身份证$输出=节点页面视图(节点加载(1221));它至少在D6上起作用。为什么不使用path模块(在内核中)。转到别名页/admin/build/path/add或使用PHP函数path\u set\u Alias?
/**
* Implementation of hook_menu
*/
function modulename_menu() {
$items = array();
// For department and having nice URL's for their profile pages.
$items['my/nice/url/profile/%'] = array(
'description' => 'This page holds a view that shows profiles based on the %',
'page callback' => 'website_profile_load',
'page arguments' => arg(4),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Menu path callback
*/
function website_profile_load($id = NULL) {
// Rename the query internally since other functions base the design
// on the way the query is structured and not simply by the node which
// is currently loading.
if(!empty($id)) {
$path = $_GET['q'] = 'node/1221/profile/id/' . $id;
}
// Use ctools function to correctly display node view since
// this site heavily uses ctools rendering for panels and
// web parts / web pages.
drupal_load('module', 'page_manager');
ctools_include('node_view', 'page_manager', 'plugins/tasks');
if(function_exists('page_manager_node_view')) {
$output = page_manager_node_view(node_load(1221));
} else {
// Will display incorrectly but still load the UI
$output = node_page_view(node_load(1221));
}
return $output;
}