0
我在drupal6中工作,並且新增了drupal。我在drupal網站中創建了一個自定義的帳戶模塊。在drupal中,設計集成的方式是困難的,因爲他們正在展示什麼是從回調函數返回的視圖。但我的問題是我可以創建一個自定義的PHP頁面,並顯示該頁面作爲我的模塊查看頁面?這是可能的嗎?在drupal6中爲模塊創建一個php頁面視圖
我在drupal6中工作,並且新增了drupal。我在drupal網站中創建了一個自定義的帳戶模塊。在drupal中,設計集成的方式是困難的,因爲他們正在展示什麼是從回調函數返回的視圖。但我的問題是我可以創建一個自定義的PHP頁面,並顯示該頁面作爲我的模塊查看頁面?這是可能的嗎?在drupal6中爲模塊創建一個php頁面視圖
首先,您必須實施hook_menu
所以:
function YOURMODULE_menu()
{
$items = array();
// this would create a Menuitem in Adminmenu, but you can specify an other url for different locations
$items["admin/settings/YOURMODULE"] = array(
"title" => "Translateable Menu Name",
"access arguments" => array("access administration pages"),
"page callback" => "drupal_get_form", // function, that will be called for this menuitem
"page arguments" => array("YOURMODULE_menu_admin"), // Argument givven to the page_callback function
"type" => MENU_NORMAL_ITEM,
);
return $items;
}
查看hook_menu | Drupal 6 | Drupal API瞭解詳情。 在第一個例子你的函數將drupal_get_form
被調用,你可以在其中創建某些形式是這樣的:
function YOURMODULE_menu_admin()
{
// YOURMODULE_element_name is the name of the form element
$form['YOURMODULE_element_name'] = array(
'#type' => 'textfield',
'#title' => t('Title of the textfield'),
'#default_value' => variable_get('YOURMODULE_element_name', ""),
'#size' => 2,
'#maxlength' => 2,
'#description' => t("Description of your formfield."),
'#required' => TRUE,
);
return system_settings_form($form);
}
螞蟻,如果你想創建一個完整的自定義頁面,用您自己的內容,你可以指定你的在hook_menu
function YOURMODULE_menu()
{
$items = array();
// this would create a Menuitem in Adminmenu, but you can specify an other url for different locations
$items["YOUR_CUSTOM_PATH"] = array(
"title" => "Translateable Menu Name",
"access arguments" => array("access custom module"), // you can define your own permission here
"page callback" => "your_custom_page", // function, that will be called for this menuitem
"type" => MENU_NORMAL_ITEM,
);
$items["YOUR_CUSTOM_PATH_FOR_IMAGE"] = array(
"title" => "An image output page",
"access arguments" => array("access custom module"), // you can define your own permission here
"page callback" => "your_custom_image", // function, that will be called for this menuitem
"type" => MENU_NORMAL_ITEM,
);
return $items;
}
自己的回調函數,那麼你可以自由地實現這個功能,甚至可以輸出二進制數據來定義自己的頭。
function your_custom_page()
{
echo "this is my custom page";
}
function your_custom_image()
{
drupal_set_header("Content-Type: image/png");
$im = @imagecreate(110, 20);
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
// Exit here, because we don`t want the drupal footer in out Image output
if(function_exists("drupal_exit")) drupal_exit();
else
{
// Allow modules to react to the end of the page request before redirecting.
// We do not want this while running update.php.
if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') {
module_invoke_all('exit', $url);
}
exit;
}
}
任何人都可以幫助我嗎? – anoop 2013-05-15 13:59:41