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

时间:2011-07-28 10:42:24

标签: php drupal drupal-modules

我是模块开发领域的初学者,我遇到了一个问题。 我已经使用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',
 );

我的页面回调如下: -

 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;
}

1 个答案:

答案 0 :(得分:0)

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

在这种情况下,您似乎只想传递整数id,在这种情况下,您只需使用“%”。

相关问题