Additional functions in Table Delegate Class

Archived from the Xataface Users forum.

conkhikho — Wed Nov 18, 2009 7:11 pm

Hi,

What I want to do is having a utility kind of function in a table delegate class to reuse in other standard functions of the class such as afterSave and beforeSave. The function name can be

function utilityFunction($param)

Is this possible?

I’m having such a function, but calls to it cause a “call to an undefined function” error.

Thanks


shannah — Wed Nov 18, 2009 7:35 pm

It is certainly possible to do this. I can’t really comment on why the error is occuring without additional info. E.g. Where is the function defined and how is it defined. And where are you calling the function from, and how are you calling it.


conkhikho — Thu Nov 19, 2009 4:41 pm

This is how my code is organized.

This is in the assets.php

Code: Select all
`

     function getTitle(&$record){
           …
     }

     …..

     function testFunc(){} // This testFunc has nothing in its body, yet it invokes the “call to undefined function” error

     …..
     
     function beforeInsert(&$record){
          …// stuff that works fine before inserting testFunc()
         
          testFunc();
         
          …// stuff that works fine before inserting testFunc()
     }
}

?>`

Thank you.


shannah — Thu Nov 19, 2009 5:14 pm

If you define a function inside a class, then you need to call it as a method of the class.

e.g. In your case you should have

Code: Select all
function beforeInsert(&$record){           ...// stuff that works fine before inserting testFunc()                     $this->testFunc();                     ...// stuff that works fine before inserting testFunc()      }

-Steve


conkhikho — Thu Nov 19, 2009 8:06 pm

Works like a charm!! Thanks a lot for your prompt help Steve.

Tim