louisstephens Posted July 13, 2017 Posted July 13, 2017 (edited) 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 July 13, 2017 by louisstephens I just noticed the sub forum regarding Development, if someone could move this to the correct area I would appreciate it.
kongondo Posted July 13, 2017 Posted July 13, 2017 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.
louisstephens Posted July 13, 2017 Author Posted July 13, 2017 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.
louisstephens Posted July 13, 2017 Author Posted July 13, 2017 Hmm, Ill check on that, though I did add namespace Processwire; , though I take a deeper look.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now