I am pretty new to Drupal, though very familiar with PHP, and I haven't had any luck searching for a clear guide to this.

I have made a subtheme of the bootstrap theme and I am planning to import a couple dozen static documents from an existing Smarty site (somehow -- another exercise for later). But I also need a page that displays a form that allows a user to search a database (other than Drupal's).

In my case the database is called "glossary" and I have added the connection parameters to settings.php. My subtheme is called "sdny." So far I have

* studied https://www.drupal.org/node/223440#custom-suggestions
* created a node of type "basic page" with no body content;
* given it the alias "glossary";
* created a function in my template.php like so:

function sdny_preprocess_page(&$variables,$hook) {
    $path = filter_input(INPUT_SERVER,'REDIRECT_URL',FILTER_SANITIZE_STRING);
     if ('/glossary' == $path) {
            $variables['theme_hook_suggestion'] = 'page__glossary';
	}
}

* created a page--glossary.tpl.php, which looks much like its counterpart page.tpl.php in the parent theme, except that it contains
a include(__DIR__.'/glossary.php') ?> just before the closing <section> tag, and
* created a glossary.php that tries to take care of the rest: display form, validate, build SQL query, execute against database, display results (using theme('pager') for pagination).

I have succeed in getting it to load my templates and look just like the rest of the theme (yay!), but have also run into so many problems that I am wondering if this is the right approach. I've tried to use the drupal database API and set_active_db("glossary") but I keep getting exceptions because Drupal tries to query tables that don't exist in my database.

I would like to use the Drupal form api but it looks as though -- please correct me if I am mistaken -- the Drupal way is to create your own module in order to do this. I would be glad to learn module development but I have to wonder if it isn't overkill to create a full-blown module just to create a read-only interface to a database. I could do _everything_ by hand inside my glossary.php, but it does seem as though it would make sense to take advantage of the Drupal API and functions that are already loaded into memory.

Any advice would be deeply appreciated. Thanks.

Comments

Jaypan’s picture

Everything in Drupal is a module - even themes are a type of module. Well, almost everything. So creating a 'full blown' module isn't overkill, and for that matter, modules can be very tiny and lightweight.

professor_b’s picture

ah, ok -- I was wondering about that. In the meantime, I simply did all the form generation and validation and SQL-building by hand, and did manage to leverage the paging provided by the theme and some of the database API, and it's working fine. Next time, though (or maybe when I have time to take another crack at this) I will make my debut as a module developer (-: