Vad är det för fel på min array? Rader ur tabell visas inte.

Events happening in the community are now at Drupal community events on www.drupal.org.
d.holmen@gmail.com's picture

Hej gott folk,

Jag skriver en modul för tillfället som skapar en kö för utgående mail, som liknar kön för kommentarer som ska godkännas.
Jag har skapat tabellen i databasen, koden som lägger in rader i den, kod som hämtar allt och visar - men det visas inte.

Jag är inte helt säker på min kod, men jag får ut datan ur databasen, det är bara att den inte vill visas i tabellen på sidan.

Får även ett felmeddelande om tableselect, som kanske har något att göra med det hela(?).

Notice: Undefined index: #attributes i theme_tableselect() (row 3199 av drupal/includes/form.inc).

Drupal 7

<?php
/
* @file
* Administration page callbacks for the hr_torget module.
*/
/

* Form builder. Offerts from users in Branschguiden
*
* @param $arg
*   Current path's fourth component: the type of overview form ('approval' or
*   'new').
*
* @ingroup forms
* @see comment_admin_overview_validate()
* @see comment_admin_overview_submit()
* @see theme_comment_admin_overview()
* @see system_settings_form().
*/


function mymodule_admin_offer() {
// Build an 'Update options' form.
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#attributes' => array('class' => array('container-inline')),
  );

  $options['send'] = 'Skicka markerade offerter';

  $options['delete'] = 'Ta bort markerade offerter';

  $form['options']['operation'] = array(
    '#type' => 'select',
    '#title' => t('Operation'),
    '#title_display' => 'invisible',
    '#options' => $options,
    '#default_value' => 'send',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );

  // Load the offers that need to be displayed.
  $header = array(
    'date' => array('data' => t('Date'), 'field' => 'date'),
    'message' => array('data' => t('Message'), 'field' => 'message'),
    'name' => array('data' => t('Name'), 'field' => 'name'),
    'mail' => array('data' => t('E-mail'), 'field' => 'mail'),
    'phone' => array('data' => 'Telefon', 'field' => 'phone'),
    'compname' => array('data' => 'Företagsnamn', 'field' => 'compname'),
    'comptype' => array('data' => 'Företagstyp', 'field' => 'comptype'),
    'companies' => array('data' => 'Företag', 'field' => 'companies'),
   );

   // Get the offers from the db
  $query = db_select('offer', 'o');
        $query->fields('o',array('id','date','message','name','mail','phone','compname','comptype','companies')) //SELECT the fields from offer
->orderBy('id', 'DESC') //ORDER BY id
->range(0,50) //LIMIT to 50 records
->condition('o.sent', 0, '='); // already sent?

   $result = $query->execute();

  $oids = array();

  // Build a table listing the appropriate offers.
  $options = array();
  foreach($result as $company) {
//DEBUG print $company->date;
     $options[$company->id] = array(
      'date' => $company->date,
      'message' => $company->message,
      'name' => $company->name,
      'mail' => $company->mail,
      'phone' => $company->phone,
      'compname' =>$company->compname,
      'comptype' => $company->comptype,
      'companies' => $company->companies,
    );
  }

  $form['offers'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => 'Inga offerter tillgängliga.',
  );

  $form['pager'] = array('#theme' => 'pager');

  return $form;
}

Comments

#headers kan vara problemet?

bobodrone's picture

Hei!

Enligt FAPI (Form API) skall en #header vara:

$header = array(
'min_key_för_fältet' => t('min header text'),
'min_key_för_fältet2' => t('min header text2'),
'min_key_för_fältet3' => t('min header text3'),
);

Kolla på: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....

Din header skall kanske alltså se ut så här:

// Load the offers that need to be displayed.
  $header = array(
    'date' => t('Date'),
    'message' => t('Message'),
    'name' => t('Name'),
    'mail' => t('E-mail'),
    'phone' => t('Telefon'),
    'compname' => t('Företagsnamn'),
    'comptype' => t('Företagstyp'),
    'companies' => t('Företag'),
   );

Testa och återkom om det inte fungerar!

Lycka till!

/ bobodrone

Sweden

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: