Page 1 of 1
Additional functions in Table Delegate Class
Posted:
Wed Nov 18, 2009 7:11 pm
by conkhikho
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
Posted:
Wed Nov 18, 2009 7:35 pm
by shannah
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.
Posted:
Thu Nov 19, 2009 4:41 pm
by conkhikho
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.
Posted:
Thu Nov 19, 2009 5:14 pm
by shannah
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
Posted:
Thu Nov 19, 2009 8:06 pm
by conkhikho
Works like a charm!! Thanks a lot for your prompt help Steve.
Tim