通常情况下,我会采用另一种方式。我通过hook_menu()
菜单路由器项来定义内容,而不是节点内容,因为它很少直接用户可编辑。如果有很多处理,您可以将其与.module分开,并将其作为每个项目的file
。
/**
* Implementation of hook_menu().
*/
function MODULE_menu() {
$items = array();
$items['example/json'] = array(
'title' => 'JSON example',
'page callback' => '_MODULE_json',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['example/xml'] = array(
'title' => 'XML example',
'page callback' => '_MODULE_xml',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* JSON example.
*/
function _MODULE_json($string = '') {
$data = array();
$data['something'] = 0;
$data['anotherthing'] = 1;
drupal_json($data);
}
/**
* XML example. No idea if this actually produces valid XML,
* but you get the idea.
*/
function _MODULE_xml($string = '') {
$data = array();
$data['different'] = 2;
$data['evenmore'] = 3;
// Build XML
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$output .= "<data>\n";
$output .= format_xml_elements($data);
$output .= "</data>\n";
// We are returning XML, so tell the browser.
drupal_set_header('Content-Type: application/xml');
echo $output;
}
感谢您的反馈。 – awolfe76
问题是,我们需要能够经常更新,任何人都应该能够做到。使用_menu是否允许项目可编辑? – awolfe76
它可以做到。在页面回调中,你可以''node_load()'你想要的节点并返回它们纯粹的$ node-> body内容。 – scronide