[英]Drupal - Page not found for custom module
I'm fairly new to Drupal and just made my first module wich shows a form. 我对Drupal很新,只是让我的第一个模块显示了一个表单。 In the hook_menu(), I set $items['form'], as you can see below. 在hook_menu()中,我设置$ items ['form'],如下所示。 While I navigate to mysite.com/form, it doesn't show me anything, except for the theme and: Page not found, The requested page "/form" could not be found. 当我导航到mysite.com/form时,它没有向我显示任何内容,除了主题和:找不到页面,找不到请求的页面“/ form”。
I tried to clear my cache, to give my module a different name, made sure my module is enabled, nothing helps. 我试图清除我的缓存,给我的模块一个不同的名称,确保我的模块启用,没有任何帮助。 Does anyone knows what the problem might be? 有谁知道问题可能是什么? The code from the .module file is right here: .module文件中的代码就在这里:
<?php
//implements hook_permission()
function form_example_permission() {
return array(
'Submit form_example' => array(
'title' => t('Submit form_example'),
'description' => t('Submit the form_example form'),
),
);
}
//implements hook_menu()
function form_example_menu() {
$items['form'] = array(
'title' => 'My Example Form',
'type' => MENU_NORMAL_ITEM,
'acces' => TRUE,
'page callback' => 'drupal_get_form()',
'page arguments' => array('form_example_form'),
'acces arguments' => array('acces content'),
);
return $items;
}
//implements hook_form()
function form_example_form($form, &$form_state) {
$form['mynumber'] = array (
'#type' => 'textfield',
'#title' => t('My Number'),
'#size' => 10,
'#maxlength' => 10,
'#required' => TRUE,
'#description' => t('Please enter a valid number'),
);
$form['mytextfield'] = array(
'#type' => 'textfield',
'#title' => t('My Textfield'),
'#size' => 60,
'#maxlength' => 128,
'#required' => TRUE,
);
$form['mytext'] = array(
'#title' => t('My Textarea'),
'#type' => 'textarea',
'#description' => t('Enter some text'),
'#default value' => '',
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Add item'),
);
return $form;
}
'page callback' => 'drupal_get_form()
is wrong, you need to remove brackets from function name. 'page callback' => 'drupal_get_form()
错误,你需要从函数名中删除括号。 The right implementation will be page callback' => 'drupal_get_form
. 正确的实现将是page callback' => 'drupal_get_form
。 And also acces => TRUE
is wrong, it must be 'access callback', and if you set fixed TRUE value then you don't need to specify access arguments
key. 并且acces => TRUE
是错误的,它必须是'访问回调',如果你设置固定的TRUE值,那么你不需要指定access arguments
密钥。 Because access callback
return TRUE anyway. 因为无论如何access callback
返回TRUE。 For further reading .. 进一步阅读 ..
UPDATE: Example: 更新:示例:
function form_example_permission() {
return array(
'submit form_example' => array(
'title' => t('Submit form_example'),
'description' => t('Submit the form_example form'),
),
);
}
//implements hook_menu()
function form_example_menu() {
$items['form'] = array(
'title' => 'My Example Form',
'type' => MENU_NORMAL_ITEM,
'access callback' => 'user_access',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_example_form'),
'access arguments' => array('submit form_example'),
);
return $items;
}
(you had a typo in you code) Don't forget to flush the cache. (你的代码中有一个拼写错误)不要忘记刷新缓存。
Please change speling a acces
to access
and change the drupal_get_form()
to drupal_get_form
and after clear a caches
请更改speling一个acces
来access
和更改drupal_get_form()
来drupal_get_form
后clear a caches
function form_example_menu() {
$items['form'] = array(
'title' => 'My Example Form',
'type' => MENU_NORMAL_ITEM,
'access' => TRUE,
'page callback' => 'drupal_get_form',
'page arguments' => array('form_example_form'),
'access arguments' => array('access content'),
);
return $items;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.