Jump to content

Include in Module giving weird url


Recommended Posts

So I was working on a module and trying to include a library (so I could use it across the site) using $modules->get('myModule'); . However, When I go to include the library folder (modeled after the LibFlourish module created some time ago). I keep getting: 

site/modules/MyModule/libraryName/ProcessWire\filetoinclude.php

This comes with an error notifying that "failed to open stream: No such file or directory in ...".. Is ProcessWire supposed to be in the include url, or is there a way around this? Sorry, I am quite new to working with my own modules.

 

I just noticed the sub forum regarding Development, if someone could move this to the correct area I would appreciate it.

Edited by louisstephens
I just noticed the sub forum regarding Development, if someone could move this to the correct area I would appreciate it.
Link to comment
Share on other sites

How are you including it? What's your code? Where is the location? For a file in the same location as the module, the following should suffice:

$dir = dirname(__FILE__);
require_once("$dir/FileToInclude.php");
#require_once("$dir/someFolderName/FileToInclude.php");// if in a folder

This way, __FILE__ will deal with paths rather than you.

 

 

Link to comment
Share on other sites

Thanks @kongondo, I was using: 

public function init() {
    spl_autoload_register(array($this, 'loadingMyFiles'));
  }

private function loadingMyFiles($class_name){
    include (__DIR__ . "/{$class_name}.php");
  }

I should have included that earlier. I am probably missing something important/small here. I tweaked mine to resemble what you had, but I am still getting /ProcessWire\ in the string. The file(s) I am trying to load are in a folder within the module file.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...