Additional functions in Table Delegate Class

A place for users and developers of the Xataface to discuss and receive support.

Additional functions in Table Delegate Class

Postby 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
conkhikho
 
Posts: 11
Joined: Wed Oct 07, 2009 5:57 pm

Postby 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.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby conkhikho » Thu Nov 19, 2009 4:41 pm

This is how my code is organized.

This is in the assets.php
Code: Select all
<php>

     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.
conkhikho
 
Posts: 11
Joined: Wed Oct 07, 2009 5:57 pm

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby conkhikho » Thu Nov 19, 2009 8:06 pm

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

Tim
conkhikho
 
Posts: 11
Joined: Wed Oct 07, 2009 5:57 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 19 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved