[英]Drupal 7 REST services - Suppress API output of NULL
我有一個 API 服務回調函數,它與它自己的模塊模板相關聯以提供 HTML 輸出。 根據我的理解,API 輸出的默認內容類型是application/json
,所以我必須手動將其覆蓋為text/html
。
但是,無論我嘗試什么,我仍然總是得到null
輸出。 如何抑制這種不需要的null
輸出?
custom_module.module
function api_callback_function($a) {
if (!headers_sent()) {
drupal_add_http_header('Content-Type', 'text/html');
}
print theme('custom_template_name_alias', array(
'b' => $a
));
return;
}
function custom_module_theme() {
$themes = array(
'custom_template_name_alias' => array(
'template' => 'something-only', // name of template file, sans file extension
'variables' => array(
'b' => NULL
),
)
);
return $themes;
}
something-only.tpl.php
<?php
$c = $variables['b'];
$path = drupal_get_path('module', 'custom_module');
global $base_url;
?>
<!doctype html><html class="no-js" lang="en">
<head>
<!-- HEAD related HTML code comes here -->
</head>
<body>
<div>Current value of variable 'b' = <?php echo $c; ?></div>
</body>
</html>
嘗試將api_callback_function
return
替換為die()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.