通常、私はこれについて別の方法で行きます。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;
}