我在 drupal6 工作,是 drupal 的新手。我在 drupal 网站上创建了一个自定义我的帐户模块。在 drupal 中,设计集成的方式有些困难,因为他们展示了它们从回调函数返回的视图。但我的问题是我可以创建一个自定义 php 页面并将该页面显示为我的模块视图页面吗?这是可能的吗?
问问题
78 次
1 回答
0
首先你必须实现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;
}
见钩子菜单 | 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);
}
Ant 如果你想创建一个完整的自定义页面,有你自己的内容,你可以在 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;
}
}
于 2013-10-14T08:02:40.163 回答