无法从自定义模块打开编辑表单(开始模块开发)


Can't open the edit form from my custom Module (Beginning module development)

我是模块开发领域的初学者,我面临着一个问题。我已经创建了带有hook_menu函数的.module文件,其中包含以下代码:

  $items['game/add_tournament/view_tournament']=array(          
 'title'=>'View Tournament',
 'description'=>'Tournament View',
 'page callback'=>'game_view_tournament_page',
 'access callback'  => 'user_access',
 );

My Page回调如下:-

 function game_view_tournament_page() {         
  $header_table_edit = array( 
// first cell has the following text 'Title' 
 array('data' => t('Tournament Name')), 
// second cell has the following text 'Link to edit'
array('data' => t('No of Weeks')),
array('data' => t('Start Date')),
array('data' => t('End Date')),
array('data' => t('Edit'))
);
$query = db_query

( "select tournament_id ,tournament_name ,tournament_no_of_weeks ,tournament_start_date ,tournament_end_date from {tournaments} ");

   while ($data = db_fetch_object($query)) 
{
    $rows_table_edit[] =  array(
    array('data' => l($data->tournament_name,   'game/add_tournament/view_tournament/' . $data -> tournament_id)),
    array('data' => t($data->tournament_no_of_weeks)),
    array('data' => t($data->tournament_start_date)),
    array('data' => t($data->tournament_end_date)),  
    array('data' => l(t('Edit'),'game_tournament_edit/'.$data -> tournament_id.'/edit')) ); 
}

   $caption_table_edit = t('Table for edit nodes');
    return theme('table', $header_table_edit, $rows_table_edit);
}

到目前为止,网站运行良好。现在问题来了。在这一点上,我假设另一个回调将被调用,当我点击编辑按钮,回调也应该在我的hook_menu函数中注册。在这里,我不知道这个方法是否被回调。因为每次我点击编辑按钮,我得到一个页面没有发现错误。以下是回调

  $items['game_week_edit/%game_abc/edit']=array(            
'type' => MENU_LOCAL_TASK,   
 'access arguments' => array('access content'),
    'page callback' => 'game_week_edit_page',
    'page arguments' => array(1),
    );
  // The above code is in hook_menu function and the following code is outside hook_menu . Let me know if i am doing anything wrong.
 function game_week_edit_page($abc_id){
return drupal_get_form('game_week_edit_form',$abc_id);
     }

   function game_week_edit_form( &$form_state, $abc_id) {           
$form = array();
$options = array();
$sql = "SELECT game_week_id,tournament_id,start_time,open_time,close_time FROM {game_week} where game_week_id='$abc_id'";
$r = db_query($sql);
$sql_tournament = "SELECT tournament_name FROM {tournaments} ";
$r_tournament = db_query($sql_tournament);

       while ($row = db_fetch_array($r_tournament)) {
$options[$row['tournament_name']] = $row['tournament_name'];
}
while ($row = db_fetch_object($r)) 
{
 $form['tournament_name'] = array(
       '#type' => 'select',
       '#required'=>true,
       '#title' => t('Select Tournament'),
       '#options' => $options,
         '#weight'=>1,
         '#description' => t('<br>'),
       );
$form['start_time'] = array(
      '#type' => 'textfield',
      '#required'=>true,
      '#value'=>t($row->start_time),
      '#title' => t('Enter Start Time'),
      '#size'=>40,
      '#maxlength'=>128,
      '#weight'=>2,
      '#description' => t('Please enter start time.'),
      );
$form['open_time'] = array(
      '#type' => 'textfield',
      '#required'=>true,
      '#value'=>t($row->open_time),
      '#title' => t('Enter Tournament Start Time'),
      '#size'=>40,
      '#maxlength'=>128,
      '#weight'=>3,
      '#description' => t('Booking open time.'),
      );
$form['close_time'] = array(
      '#type' => 'textfield',
      '#required'=>true,
      '#value'=> t($row->close_time),
      '#title' => t('Booking close time'),
      '#size'=>40,
      '#maxlength'=>128,
      '#weight'=>4,
      '#description' => t('Booking close time.'),
      );
$form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Update Tournament'),
      '#weight'=>5
     );
}
return $form;
}

在hook_menu中,尽量不要在编辑项中命名通配符。"%game_abc"告诉Drupal调用一个函数"game_abc_load"(即"_load"所附加的名称),并使用返回值作为页面回调"game_week_edit_page"的第一个参数。如果没有这样的功能,就会出现问题。

在这种情况下,看起来您只想传递整数id,在这种情况下,您可以使用"%"。