Hi All,
I'm new to developing in PHP and Processwire so apologies in advance for any stupid questions.
I'm working on developing a module for the Twilio Channels API. I'd like to be able to input the API credentials into the modules settings page and then call the API credentials in module functions and, where necessary, in templates.
I can currently add the API details and save them in my module config file, no problem.
ModuleConfig file:
<?php
class TwilioChannelsConfig extends ModuleConfig {
public function getDefaults() {
return array(
"id" => "",
"token" => "",
"from_number" => ""
);
}
public function getInputfields() {
$inputfields = parent::getInputfields();
$f = $this->modules->get('InputfieldText');
$f->attr('name', 'id');
$f->label = $this->_('Twilio SID');
$f->notes = $this->_('From your Twilio Account (at https://www.twilio.com/user/account)');
$f->columnWidth = 50;
$inputfields->add($f);
$f = $this->modules->get('InputfieldText');
$f->attr('name', 'token');
$f->label = $this->_('Twilio API Token');
$f->columnWidth = 50;
$inputfields->add($f);
$f = $this->modules->get('InputfieldText');
$f->attr('name', 'from_number');
$f->label = $this->_('Your Twilio Number');
$f->description = $this->_('Will be used as the "from" number when sending messages or starting calls.');
$inputfields->add($f);
return $inputfields;
}
}
What I'd like to be able to do is either call getInputFields() in a template, something similar to this:
$moduleConfig = $modules->get('TwilioChannelsConfig');
echo "<p>" . $moduleConfig->getInputFields('id') . "</p>";
or to call the credentials to my .module file.
I've tried a few different approaches but can't get it to work. Not sure what I'm missing.
Thanks in advance for any help.