Using $this->data in a php function

Access form data in an external PHP function within ChronoForms.

Overview

The issue occurs because passing the $this object directly to a custom function causes a PHP error, as $this is not available in that context.
Instead of passing $this, retrieve the specific data using the get() method with the read function's name and pass that result to your external function.

Ni NickOg 04 Jun, 2017
Hi Max

This follows on from your reply here regarding this use of $this->data.

I have successfully read data from two tables. {debug:} shows that the data is in $this. The processing is a bit complex so I now want to access that data in an external PHP function.
I have set up a function
$blnSuccess=MandP_function($this);
and the php function called is simply
function MandP_function($this) {
  var_dump($this->data);
  return TRUE;
}
.
That throws an error

0 - Using $this when not in object context

which is, I believe, a PHP error, the fix for which Is beyond my current knowledge.

So the questions are -
[list=]How can I get around that error and access my data?[/list]
or
[list=]How can I just pass my data to that function?[/list]

If I modify my function to be
$blnSuccess=MandP_function($this->data);

and the called function to be
function MandP_function($this) {
  var_dump($this);
  return TRUE;
}


then the data I get from the dump is
array(7) { ["conn"]=> string(20) "ManageMemberPartners" ["user_id"]=> string(4) "1493" ["function"]=> string(4) "SWAP" ["event"]=> string(4) "view" ["Itemid"]=> string(3) "610" ["option"]=> string(23) "com_chronoconnectivity6" ["view"]=> string(10) "connection" } 

No data from the db read. That data is there - if I dump all of $this in the first example - I can see it - just can't work out how to get to it!

Hope this is clear..😲😲
Max_admin Max_admin 04 Jun, 2017
Answer
Hi Nick,

Just pass the read data results to your function, you can get it with this line:


$this->get("read_data_function_name");


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Ni NickOg 04 Jun, 2017
Hi Max

Thanks for the fast response - that works a treat.

Regards

Nick
This topic is locked and no more replies can be posted.