0
votes

I'm working on a site where there will be several admin pages that have intense logic in them. Let's take an example. I want a page that lists certain nodes and allows you to add or remove them, or do other actions on them.

Now, I can create a normal page in Drupal and select the input filter as "php code" and then just add the following line:

<?php executeTheCodeThatDoesEverythingForThisPage(); ?>

And I can put this method in a module.

However, this is not ideal, as a DB call is still made to find out what method must be called. I want to:

  1. Entirely skip the DB call
  2. Have a folder, e.g. pages, that stores all my custom pages, e.g. aboutus.php, mystuff.php
  3. Still have access to all the drupal functions in this file

Anybody know how I can do this?

<<-- EDITED -->>

If I can't skip the DB query, can someone tell me the best way to include data from a static php file? Is there a module for this, or should I just add the following code:

include_once "myFile.php";
2
If your code comes from the database, the only way you could skip that part was if you use cache.. - yoda

2 Answers

1
votes

To include files, you need to look at the menu system, in particular page callbacks:

http://drupal.org/node/146172

0
votes

Supposing that the myFile.php file is copied in the directory containing the module itself, you could use code similar to the following one.

function mymodule_menu() {
  $items['mymodule_path'] = array(
    'page callback' => 'mymodule_path_output',
    'access arguments' => array('access content'),
  );

  return $items;
}

function mymodule_path_output() {
  module_load_include('php', 'mymodule', 'myFile');

  // …
}

The implementation of hook_menu() I used is minimal; see the documentation for more information about the hook.