Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing $this inside static methods and methods called by this method
    primarykey
    data
    text
    <p>How do I use <code>$this-&gt;var1</code> inside a method that is called from a static method? I have this method:</p> <pre><code>static public function getModuleConfigInputfields(array $data) { $fields = new InputfieldWrapper(); $modules = Wire::getFuel('modules'); $field = $modules-&gt;get("InputfieldText"); $field-&gt;attr('name+id', 'apiKey'); $field-&gt;attr('value', $data['apiKey']); $field-&gt;label = "API Key (Developer Key)"; $field-&gt;description = 'Enter the API key'; $fields-&gt;append($field); $field = $modules-&gt;get("InputfieldSelect"); $field-&gt;attr('name+id', 'list_id'); $mailing_lists = self::get_mc_lists(); foreach($mailing_lists['data'] as $list) { $field-&gt;addOption($list-&gt;list_name, $list-&gt;list_id); } $field-&gt;label = "Mailing list"; $field-&gt;description = 'Choose a mailing list'; $fields-&gt;append($field); return $fields; } </code></pre> <p>And I want to call this method:</p> <pre><code>public function get_mc_lists() { $api = new MCAPI($this-&gt;apiKey); $retval = $api-&gt;lists(); if ($api-&gt;errorCode){ return array('errorcode' =&gt; $api-&gt;errorCode, 'errormessage' =&gt; $api-&gt;errorMessage); } else { return array('data' =&gt; $retval['data'], 'total' =&gt; $retval['total']); } } </code></pre> <p>But I am getting this error:</p> <blockquote> <p>Error Using $this when not in object context (line 31</p> </blockquote> <p>Line 31, which is: <code>$api = new MCAPI($this-&gt;apiKey);</code></p> <p>So how can I fix this, work around this... I am really stuck on this</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload