Soma Posted February 5, 2014 Share Posted February 5, 2014 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"); Link to comment Share on other sites More sharing options...
WillyC Posted February 5, 2014 Share Posted February 5, 2014 . how abut class_exists("moduule") ? 1 Link to comment Share on other sites More sharing options...
Soma Posted February 5, 2014 Author Share Posted February 5, 2014 Ahhh yes of course. But as a $mouldes->isInstalled("module") already exists it might be cool to add that too Link to comment Share on other sites More sharing options...
Soma Posted February 5, 2014 Author Share Posted February 5, 2014 Ok , class_exists() doesn't work as the class is loaded even if the module not loaded. Link to comment Share on other sites More sharing options...
Wanze Posted February 5, 2014 Share Posted February 5, 2014 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? Link to comment Share on other sites More sharing options...
Soma Posted February 5, 2014 Author Share Posted February 5, 2014 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. Link to comment Share on other sites More sharing options...
ryan Posted February 7, 2014 Share Posted February 7, 2014 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 } 7 Link to comment Share on other sites More sharing options...
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