私のモジュールからの定義されたメニューは、404エラーを返します
-
25-09-2019 - |
質問
私はDrupalのに新しいです。私は次のコードでcontace1モジュールを作成しています:
contace1.info
; $Id$
name = Contact1
description = Show how to build contact form
package = Pro Drupal Development
core = 6.x
contact1.module
// $Id$
/**
* @file
* practice to build form
*/
/**
* Implimentation of hook_menue().
*/
function contact_menu()
{
$items['contact1'] = array(
'title' => 'Contact',
'page callback' => 'contact_page',
'access argument' => array('access content'),
'type'=>MENU_CALL_BACK,
'access callback' => TRUE,
);
return $items;
}
/**
* menu callback
* called when user goes to http://localhost/drupaldemo/?q=contact
*/
function contact_page()
{
$output = t('You can leave a message using the contact form below.');
//Return the html generated from $form data structure.
$output.= drupal_get_form('contact_nameform');
return $output;
}
/**
* define the form
*/
function contact_nameform()
{
$form['user_name']= array(
'#title' =>t('Your Name'),
'#type' => 'textfield',
'#description' => t('Please enter your name.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
) ;
return $form;
}
/**
* validate the form
**/
function contact_nameform_validate()
{
if($form_state['values']['user_name']=="")
{
form_set_error('user_name',t('Please enter your name.'));
}
}
/**
* handle post validation form submition
*/
function contact_nameform_submit($form ,&$form_state)
{
$name=$form_state['values']['user_name'];
drupal_set_message(t('Thanks for filling out the form, %name',array('%name'=>$name)));
}
イム私は新しい連絡先フォームを作成しようとしました。このコード
しかし、それは直接見られないページを与える任意のリンクを表示し、オープニングページではありません。
正しい解決策はありません
他のヒント
すべてのまず、MENU_CALL_BACK
はDrupalの中で定義されていません。何が書きたかったことは、メニューのルータにメニュー項目を登録するMENU_CALLBACK
、です。こちらの商品は、通常、目に見えるメニューには表示されません。隠されたメニュー項目と考えてください。あなたがしたい場合は目に見える、使用MENU_NORMAL_ITEM
ます。
「型」= MENU_CALL_BACK - メニューは、コールバックで、あなたはMENU_NORMAL_ITEMに設定するか、手動でcontact1ページへの管理ページでメニューを作成する必要があります。リフレッシュキャッシュ。
I完全Vandykから「プロDrupalの開発」を読んで、あなたにお勧めします、例は、フォームを作成する方法があります:)
コード内の最初のエラーは、モジュールがcontact1.module命名されている場合は、すべてのフック、それを実装がcontact1_で始まる名前を持つべきである、ということです。連絡先モジュールはDrupalの6ですでにあるとしてあなたは、その後、あなたのモジュールの機能の名前でcontact_を使用しないでください。あなたのモジュールは、Drupalの6のためである場合には、モジュール間の競合が存在することになる。
2番目のエラーは、使用している定数はMENU_CALLBACK
、ないMENU_CALL_BACK
ということです。
、それに付属している情報ファイルがないcontace1.info、contact1.info名前を付ける必要があります。あなたは間違ってそのファイルの名前、Drupalの6以降を使用する場合は、インストールできるモジュールのリストにあなたのモジュールを表示してはいけません。
こんにちは、このコードを使用してみてください。
/**
* menu callback
*
*/
function contact_page()
{
$output = array(
'item 1' => array(
"#type" => 'markup',
'#markup' => t('You can leave a message using the contact form below.'),
),
'item 2' => array(
"#type" => 'markup',
'#markup' => drupal_get_form('contact_nameform'),
),
);
return $output;
}
/**
* define the form
*/
function contact_nameform($form, $form_state)
{ ..........
.......
ここで、私はセットののマークアップの内容と形式とリターン出力するタイプ、またの contact_nameform($形、$ form_state)の
のパラメータを設定します