1

I searched for an explanation to this issue but didn't find anything. I have other sites where this is working but not in this one.

So, my module info file (draws.module):

name = draws
description = Draws custom module
package = Draws Modules
core = 7.x

files[] = draws.fixturesSavings.inc

In my draws.module I have this function (lines 289 to 231):

function saveToDatabase($response) {
    fixtures_saveToDatabase($response);
}

And then in the same folder of my draws.module I have the inc file (draws.fixturesSaving.inc):

<?php
function fixtures_saveToDatabase($response) {

And when I call function saveToDatabase, I get the following error:

Error: Call to undefined function fixtures_saveToDatabase() in saveToDatabase() (line 290 of /home/.../sites/all/modules/custom/draws/draws.module).

What am I doing wrong here?

3

files (Optional)

Drupal supports a dynamic-loading code registry. To support it, all modules must declare any code files containing class or interface declarations in the .info file, like so:

name = Really Neat Widget
...
files[] = tests/example.test

When a module is enabled, Drupal will rescan all declared files and index all the classes and interfaces that it finds. Classes will be loaded automatically by PHP when they are first accessed.

Currently this mechanism does not natively support namespaced classes.

Source: Writing module .info files (Drupal 7.x)

This approach only works with Object Oriented PHP. You would have to create a class.

If you want to keep with your current approach, add this to the top of the draws.module file after the <?php open tag.

module_load_include('inc', 'draws', 'draws.fixturesSavings');
12
  • HI @No Sssweat, thanks again for your support. Your suggestion to use module_load_include was the first one I used but it also gives the same error. That's why I tried to use the info file approach. This is very strange because it alwasys worked before.
    – zephirus
    Aug 25 '20 at 9:22
  • @zephirus is draws.fixturesSaving.inc located in the module's root/main folder? or do you have it inside a sub folder?
    – No Sssweat
    Aug 25 '20 at 9:29
  • the files are all on the same folder. sites/all/modules/custom/draws/
    – zephirus
    Aug 25 '20 at 9:33
  • 1
    Damn, I have a typo in the inc filename. Even in this post I have that typo and it was not noticable at first glance. How did I not noticed this? Well, I appologize for the time you spent on this and again, I really appreciate your help. Btw, I will still try to change my module to use OO.
    – zephirus
    Aug 25 '20 at 11:12
  • 2
    @zephirus heh, I didn't notice the extra "s" on the inc file name. I just took your files[] = value. Well glad the mystery is solved.
    – No Sssweat
    Aug 25 '20 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.