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

发布于 2024-11-26 13:07:19 字数 4018 浏览 1 评论 0原文

我是模块开发领域的初学者,我面临一个问题。 我已经使用 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;
}

I am a beginner in the module development field and i am facing a problem.
I have created the .module file with the hook_menu function having following peice of code :-

  $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 callback is following :-

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

Till this point the site works fine. Now comes the problem.
At this poinit i assume that another callback will be called when i hit edit button and that callback also should be registered in my hook_menu function.
Here i don't know if this method is being called back or not .Since everytime i hit edit button i get a Page not found error. The following is the callback

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜味超标? 2024-12-03 13:07:19

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

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

In hook_menu, try not naming your wildcard in the edit item. "%game_abc" is telling Drupal to call a function "game_abc_load" (that is, the name appended by "_load") and use the returned value as the first argument to your page callback "game_week_edit_page". If you don't have such a function, there will be problems.

In this case it looks like you just want to pass the integer id, in which case you can just use "%".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文