如何$this->var1
在从静态方法调用的方法中使用?我有这个方法:
static public function getModuleConfigInputfields(array $data) {
$fields = new InputfieldWrapper();
$modules = Wire::getFuel('modules');
$field = $modules->get("InputfieldText");
$field->attr('name+id', 'apiKey');
$field->attr('value', $data['apiKey']);
$field->label = "API Key (Developer Key)";
$field->description = 'Enter the API key';
$fields->append($field);
$field = $modules->get("InputfieldSelect");
$field->attr('name+id', 'list_id');
$mailing_lists = self::get_mc_lists();
foreach($mailing_lists['data'] as $list)
{
$field->addOption($list->list_name, $list->list_id);
}
$field->label = "Mailing list";
$field->description = 'Choose a mailing list';
$fields->append($field);
return $fields;
}
我想调用这个方法:
public function get_mc_lists()
{
$api = new MCAPI($this->apiKey);
$retval = $api->lists();
if ($api->errorCode){
return array('errorcode' => $api->errorCode, 'errormessage' => $api->errorMessage);
} else {
return array('data' => $retval['data'], 'total' => $retval['total']);
}
}
但我收到此错误:
不在对象上下文中使用 $this 时出错(第 31 行
第 31 行,即:$api = new MCAPI($this->apiKey);
那么我该如何解决这个问题,解决这个问题......我真的被困在这个问题上
提前致谢!