Calling functions inside Custom.php helper file

bggann

Active Member
Fabrik has the ability to load a custom helper file - as an alternative to using "require" or "require_once" in calcs.
If you put a file called Custom.php in /libraries/fabrik/fabrik/helpers and then call
FabrikCustom::doMyThing() in your code Fabrik will look in custom.php for the function doMyThing() and execute it. (there is an example file in there called CustomSample.php)

My challenge is this.
I call a function inside Custom.php and that function calls another function in Custom.php.
It does not seem to work - it can't find the 2nd function. Is there a way to do that?

Example (silly example code)

My calc element is
$parameter = '{placeholder}';
$answer = FabrikCustom::doThingOne($parameter);
return $answer;

In custom.php are the two functions (this is not the full custom.php)
---------
public static function doThingOne($parameter) {
$example = $parameter * 2;
$new_answer = FabrikCustom::doThingTwo($example);
return $new_answer;​
}

public static function doThingTwo($example) {
$stuff_I_did = $example * 2;
return $stuff_I_did;​
}
-----------
What I want to happen is
-> The calc element calle doThingOne()
-> doThingOne() calls doThingTwo()
-> doThingTwo() returns an answer to doThingOne
-> doThingOne() returns an answer to the calc
-> The calc returns to the form.

What does happen
-> doThingOne() hangs with a spinner on the call to doThingTwo()

It appears that doThingTwo() is not defined in the context of doThingOne()

Any way around this?
 
It looks like you have a defined class called FabrikCustom inside this file? If so you could try self::doThingTwo($example). Without seeing the entire file it is hard to be sure.
 
This is the first time I've used a helper like this. I'm going to work on the wiki page - this is very useful if you have a complex form with lots of calcs or things like that.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top