britnell Posted February 17, 2019 Share Posted February 17, 2019 Hi all, I'm new to Processwire and PHP. I'm trying to adapt a module I found which interacts with Twilio. I can install the module no problem and save settings but when calling a module function in a template I get the error: Quote Fatal error: Uncaught Error: Call to a member function hi() on null in /opt/lampp/htdocs/processwire/site/templates/twiliochannels.php:18 Stack trace: #0 After getting similar errors with more complex functions I've tried simplifying the function as much as possible. My template is: Quote <?php namespace ProcessWire; include('./_head.php'); ?> <div id='content'><?php $module = $modules->get('TwilioChannelsConfig'); echo "<p>" . $module->hi() . "</p>"; ?></div> and my .module file is: Quote class TwilioChannels extends WireData implements Module, ConfigurableModule { public function init() { } } my module config file is: Quote <?php class TwilioChannelsConfig extends ModuleConfig { public function hi() { return "Hi there "; } } I've tried adding hi() to both the module config file and the .module file. I presume it needs to be in the .module file but neither work. Thanks in advance for any help given! Link to comment Share on other sites More sharing options...
Autofahrn Posted February 17, 2019 Share Posted February 17, 2019 If you see that "call ... on null", then your $module variable is null. Are you certain that installing the module actually worked? I at least miss something like a getModuleInfo method. Link to comment Share on other sites More sharing options...
britnell Posted February 17, 2019 Author Share Posted February 17, 2019 Hi Autofahrn, thanks for replying. Yes, the module installs without error and allows me to enter details on the module settings page. Link to comment Share on other sites More sharing options...
britnell Posted February 17, 2019 Author Share Posted February 17, 2019 To add to the previous reply. I've tried printing the module info in my template to confirm the install and I get $moduleInfo = $modules->getModuleInfo('TwilioChannelsConfig'); echo "<p>" . implode(" ", $moduleInfo) . "</p>"; and I get Quote Notice: Array to string conversion in /opt/lampp/htdocs/processwire/site/templates/twiliochannels.php on line 7 0 TwilioChannelsConfig 0 0.0.0 Inactive Array Array Array Array 0 Unable to locate module This is despite being able to edit the module settings via the admin page. Link to comment Share on other sites More sharing options...
Robin S Posted February 17, 2019 Share Posted February 17, 2019 If you include a TwilioChannelsConfig.php file with your TwilioChannels module (see the blog post that introduced this approach), this file is only for defining the config fields for the module. It isn't a module in its own right that you can get with $module = $modules->get('TwilioChannelsConfig'). Put all your methods - including your hi() method - into the main TwilioChannels module file. $module = $modules->get('TwilioChannels'); echo "<p>" . $module->hi() . "</p>"; 1 Link to comment Share on other sites More sharing options...
britnell Posted February 18, 2019 Author Share Posted February 18, 2019 Hi Robin, it's working now I've put my functions in the module file, not the config file. Apologies for the stupid question and thanks for your help! 1 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