custom function in logic hook

I just made my first before_save logic hook for SuiteCRM and it seems to be working fine. :woohoo:

Yet I came across a little problem. Maybe you can help me understand this.

So, in my script (referenced in logic_hooks.php), I have the following structure:


class A {
   function A {
      function B() {}
      B();
   }
}

my logic hook never worked correctly this way. I tried also putting the FunctionB outside FunctionA, but in the same ClassA. That also didn’t work.


class A {
   function A {
      B();
   }
   function B() {}
}

My workaround was to simply add the code of function B() multiple times inside function A. But that makes for ugly and redundant code.

How / where can I define a custom function that is run in function A (which is triggered by a logic hook)?

You can try to use the following framework to create your logic hook as an installable package (this makes it very easy for you to reuse it in another installation).

https://github.com/audoxcl/SugarCRMLogicHooks

If you look at the manifest file you will notice that each of the functions present in the class is defined separately: maybe this is the problem.

Apologies if I’ve misread, but isn’t this a PHP / Class question? To call a class function (or ‘method’) you need to explicitly say where it is, so…

class A {
    function A() {
        // ...
        $this->B();
        // ...
    }
    function B() {
        // ...
    }

Thanks hostcommsteve,

Now everyone knows I have no clue what I’m doing - but getting pretty far despite this fact! :slight_smile:

You’re most likely correct that this is the issue, I’ll try it soon and report back.

that was it, works fine with $this->function();

My first introduction to PHP classes :slight_smile:

Thanks again!