Create a standard page and table in drupal module with PHP

I created a module with a simple menu structure. I can programmatically get an idea of ​​all my students in PHP. Now I want to return all students to a page in a simple table.

  • How to create a standard page?
  • How to return values ​​in a simple table?

Table structure

UGhentID Student Name Student Name Student Location

12874749 Smith Nick New York,,.

+5
source share
3 answers

If you want to create a new page, you need to use hook_menu in the module.

For instance:

/**
 * Implementation of hook_menu.
 */
function mymodule_menu() {
  $items = array();

  $items['myPage'] = array(
    'title' => 'Finances',
    'page callback' => 'mymodule_page',
    'access callback' => 'user_access',
    'access argument' => array('access nodes'),
  );
  return $items
}

/**
 * Page callback
 */
function mymodule_page() {
  $output = mymodule_table();
  return $output;
}

, "mymodule_table()" , .

function mymodule_table() {
    $rows = array();
    // build the table header
    $header = array();
    for ($i = 1; $i <= 5; $i++) {
      $header[] = array('data' =>  $i, 'class' => 'header-class');
    }
    $row = array();
    for ($i = 1; $i <= 5; $i++) {
      $row[] = array('data' =>  $i, 'class' => 'row-class');
    }
    $rows[] = array('data' => $row);
    $output .= theme('table', $header, $rows, $attributes = array('class' => 'my-table-class'));
    return $output;
}

a 5 .

+16

, " ", , , , (http://drupal.org/project/examples), , page_example.

Drupal theme_table, . , html .

+4

@Haza ​​ , Drupal 7:

function mymodule_table() {
    $rows = array();
    // build the table header
    $header = array();
    for ($i = 1; $i <= 5; $i++) {
      $header[] = array('data' =>  $i, 'class' => 'header-class');
    }
    $row = array();
    for ($i = 1; $i <= 5; $i++) {
      $row[] = array('data' =>  $i, 'class' => 'row-class');
    }
    $rows[] = array('data' => $row);
    $data = array(
        'header' => $header,
        'rows' => $rows,
        'attributes' => $attributes
    );
    $output = theme('table', $data);
    return $output;
}
+2

All Articles