hook_menu 给出 404
我正在尝试在 Drupal 6.20 中创建一个简单的模块,如下所示:
<?php
function example_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('This module implements an example form.');
}
}
function example_menu($may_cache) {
$items = array();
if ($may_cache)
{
$items[] = array(
'path' => 'example',
'title' => t('Example'),
'callback' => 'example_page',
'access' => TRUE,
'type' => MENU_NORMAL_ITEM
);
}
return $items;
}
function example_page() {
return drupal_get_form('example_page_form');
}
function example_page_form() {
$form['fullname'] = array(
'#type' => 'textfield',
'#title' => t('Enter your full name'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function example_page_form_submit($form_id, $form_values) {
...some code
}
但是每当我输入 http://mysite.com/example ,它被重定向到 404。请帮忙。我对 Drupal 技术非常陌生。除了 .info 和 .module 文件之外,是否还需要更多文件?
谢谢。
I am trying to create a simple module in Drupal 6.20 as follows:
<?php
function example_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('This module implements an example form.');
}
}
function example_menu($may_cache) {
$items = array();
if ($may_cache)
{
$items[] = array(
'path' => 'example',
'title' => t('Example'),
'callback' => 'example_page',
'access' => TRUE,
'type' => MENU_NORMAL_ITEM
);
}
return $items;
}
function example_page() {
return drupal_get_form('example_page_form');
}
function example_page_form() {
$form['fullname'] = array(
'#type' => 'textfield',
'#title' => t('Enter your full name'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function example_page_form_submit($form_id, $form_values) {
...some code
}
But whenever i am typing in http://mysite.com/example, its getting redirected to 404. Please help. I am very new to Drupal technology. Is there ne more files needed for this apart from the .info and .module file?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经找到解决方案了对于 Drupal 6.X,它的菜单挂钩应如下所示:
Ive got the solution. For Drupal 6.X it menu hook should be as follows: