Jump to content

Recommended Posts

Posted

Is it possible to have a non autoload module and then if I load it somewhere in the templates to check later if the module has been loaded?

Does this make even sense?

Example, as soon as I call the module somewhere

$modules->MyModule;

it is loaded. 

So something like this exists?

$modules->isLoaded("MyModule"); 
 
Posted

Ahhh yes of course. But as a $mouldes->isInstalled("module") already exists it might be cool to add that too :) 

Posted

What is the use case for this functionality?

I mean if you want to check if it's loaded and then load it, set singular to true.

You'll have a singleton as Pw returns the same instance on every $modules::get() call.

If you want to check if it's loaded and then NOT load it: Why would you do that? :)

Posted

Just to see if the module has been loaded anytime previously to then get data that has been set to it for output at the end of output. It's just to not load it on every request and on every page, just on pages I need it.



But I guess I can also solve it differently with populating a variable, anyway.

Posted

Actually class_exists() should work, but WillyC missed an important part. ProcessWire doesn't include module files that aren't autoload unless some information about them is requested, like $modules->getModuleInfo("className"), or the like. In the same manner, a class_exists("className"); call triggers the autoload mechanism and causes the file to be loaded. But you can prevent that by specifying false as argument 2 to class_exists():

if(!class_exists("ModuleName", false)) {
  // module is not loaded
}
  • Like 7

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...