Output variables to the plugin

Following this question , I am currently trying to redesign the plugin so that I can:

{exp:deetector} {user_agent} {hash} {/exp:deetector} 

but with the code below, I am not getting output:

 public function __construct() { $this->EE =& get_instance(); include(PATH_THIRD.'/deetector/libraries/detector.php'); $this->ua = $ua; $tagdata = $this->EE->TMPL->tagdata; $variables[] = array( 'user_agent' => $this->ua->ua, 'hash' => $this->ua->uaHash, 'browser_os' => $this->ua->full, 'browser' => $this->ua->browser, 'browser_full' => $this->ua->browserFull ); return $this->EE->TMPL->parse_variables($tagdata, $variables); } 

If I do $this->return_data = $this->ua->xx for each of the variables listed above, I get the output, but not if I parse the array of $ variables.

I also tried $variables = array , but get Undefined offset: 0.

+4
source share
2 answers

If you just use the constructor for the output, make sure that the plugin class has a public property return_data that contains parsed tags:

 $this->return_data = $this->EE->TMPL->parse_variables($tagdata, $variables); 

For any other method in the class, you can simply return the processed data according to your example.

As a side element, I suppose you are not looping any data here. Use the parse_variables_row method parse_variables_row , so additional variables, such as count , total_results and switch , are omitted. Using this method does not require a nested array, so it boils down to the following:

 $variables = array( 'user_agent' => $this->ua->ua, ... ); $this->return_data = $this->EE->TMPL->parse_variables_row($tagdata, $variables); 
+10
source

As for the other message you are referring to, no one indicated that you defined two constructor functions:

 __construct() and deetector() 

You should discard the second one and just use __construct() . Not sure if this can cause strange PHP errors.

+2
source

Source: https://habr.com/ru/post/1442658/


All Articles