Posted by caelon on April 19, 2009 at 7:41pm
I am in the process of moving a series of php pages over from another CMS to Drupal. The first page came over fairly easy as it was just a print out of a report. I have probably ten other pages to bring over begging this question...
- Each page calls two includes for DB control and misc functions. To start, I just put the includes under each module's directory. When I added the second page, Drupal threw up all over it because I was defining the same function twice. Makes sense. What I'm struggling with is where do I put (or how do I call) the includes to where they aren't tripping over each other? Googling "drupal includes" gets me nowhere fast.

Comments
There are two solutions to
There are two solutions to your problem. First use include_once() instead of include() and it will only stick the file in once. Second there is a php function called function_exists() that can be used as follows.
if (!function_exists('my_function_name')) {function my_function_name() {
//Do something.
}
}
Hope that helps.
It does, and those were
It does, and those were obvious php solutions I was too drupal-focused to think of. Thanks.
However, what is standard practice in Drupal for includes? Is there one? I was thinking one includes directory under the parent directory I'm developing this modules in.
Don VanDemark
Agile Process Manager, Blue Shield of California
I'm not aware of any
I'm not aware of any specific guidelines. However, I would recommend using the coder module to check you code and to check modules like views and cck for ideas on standard practice. I just looked at views and it appears that they do the following.
<?php...
function views_theme() {
$path = drupal_get_path('module', 'views');
require_once "./$path/theme/theme.inc";
...
?>
So basically include_once('/module_path/include_folder/filename.inc');
Hope that helps.