Ok, so I'm very new to Drupal and I'm trying to create a custom module that generates a page that the user can navigate to. When the user clicks on the page, I'm trying to retrieve the titles of all the content pieces from the database and arrange them in a table using table_theme. Everything is working except the generating of the rows in the table. It's giving me this message at the top of the page:
"Warning: Invalid argument supplied for foreach() in theme_table() (line 2107 of /srv/bindings/4d0bbd3c7be847abb26f62e0dacbcc24/code/includes/theme.inc)."
This message appears once for each title that I retrieve from the database. Here is my content_titles.module file (my custom module file):
<?php
/**
* @file
* A module that creates a page to display all existing content titles
*/
/**
* Implements hook_help()
*
* Displays help and module information
*
* @param path
* Which path of the site we're using to display help
* @param arg
* Array that holds the current path as returned from arg() function
*/
function content_titles_help($path, $arg) {
switch ($path) {
case "admin/help#content_titles":
return '' . t("Displays all existing content titles
on an overview page") . '';
break;
}
}
/**
* Implements hook_menu()
*
* Enables the module to register a link to be placed in a menu
*/
function content_titles_menu() {
$items['test/content_titles'] = array(
'title' => 'Overview Test Page',
'page callback' => 'content_titles_simple',
'access callback' => TRUE,
'expanded' => TRUE,
);
return $items;
}
/**
* Constructs the Content Titles page
*/
function content_titles_simple() {
return array('#markup' => create_content_table());
}
/**
* This function will create the table to hold the content titles in
*/
function create_content_table() {
// Retrieve content titles from the database
$results = db_query('SELECT title FROM {node}');
$header = array('Content Titles');
$rows = array();
while ($row = $results->fetchAssoc()) {
$rows[] = $row['title'];
}
print_r($rows); // FOR DEBUGGING PURPOSES
$output = theme('table', array('header' => $header,
'rows' => $rows));
return $output;
}
The problem appears to be with my use of the theme function. I don't see how any of my arguments are invalid though. I'm passing the theme type of 'table' and two arrays that I've checked aren't empty (that's why I use print_r to print the array that I store my titles from the database in). I'm pretty stumped here. Any idea what the problem could be?