Constructor of the delegate class
Posted: Tue Mar 30, 2010 2:48 pm
I'm running into a problem where I need to grasp records of parent class object from the relational table. However, if I want to get that record in each of the validation methods (fieldname__validate()), I need to make the same queries multiple times on each of these validate function, just look like this:
I'm thinking if we could have a constructor with the &$record as parameter so we can just call df_get_record() once and the member's value can be used by all methods:
So the above validate function would look like this:
Can somebody know how we can do that?
- Code: Select all
function relational_table_field1__validate(&$record, $value, &$params){
$parent_record = df_get_record('parent_table_name', array('parent_table_primary_id' => $record->val('parent_table_primary_id')));
if (!$parent_record->val('sth')) return false;
//do something
return true;
}
I'm thinking if we could have a constructor with the &$record as parameter so we can just call df_get_record() once and the member's value can be used by all methods:
- Code: Select all
class tables_relational_tablename {
var $parent_table_primary_id;
var $parent_table_sth;
tables_relational_tablename(&$record){
$parent_record = df_get_record('parent_table_name', array('parent_table_primary_id' => $record->val('parent_table_primary_id')));
$this->parent_table_primary_id = $parent_record->val('id');
$this->parent_table_sth = $parent_record->('sth');
}
}
So the above validate function would look like this:
- Code: Select all
function relational_table_field1__validate(&$record, $value, &$params){
if (!$this->parent_table_sth) return false;
//do something
return true;
}
Can somebody know how we can do that?