get relationships.ini fields
Archived from the Xataface Users forum.
pdesbois — Mon Oct 05, 2009 1:35 pm
Hello,
I have a relationships.ini file as the following:
- Code: Select all
[relation_test] action:label = "Relation Test" table_main.NAMEREF = "$NAME" table_main.SUBREF = "$SUBREF" action:order = 2 section:visible = 1
I need to make the following HTML link:
- Code: Select all
<a href="http://database_path.index.php?-table=table_main&NAMEREF=name1&SUBREF=sub1>
How to get the table name ‘table_main’ and the 2 field names ‘NAMEREF’ and ‘SUBREF’ set by the relationships.ini ?
Thanks in advance for your help,
Patrice.
pdesbois — Tue Oct 06, 2009 8:19 am
Hello,
To solve my problem I use the code hereunder :
- Code: Select all
function getRelationships($tablename, $relationname) { $rel_link = array(); $table =& Dataface_Table::loadTable($tablename); $relationships = & $table->getRelationship($relationname); if (array_key_exists('getForeignKeyValues', $relationships->_cache) == FALSE) { return $rel_link; } $rel_tablenames = array_keys($relationships->_cache['getForeignKeyValues']); if (count($rel_tablenames) == 0) { return $rel_link; } $rel_link['table'] = $rel_tablenames[0]; foreach ($relationships->_cache['getForeignKeyValues'][$rel_tablenames[0]] as $field => $val) { $this->rel_link['fields'][$field] = ereg_replace('\$', '', $val); } return $rel_link; }
With this function I’m able to create the HTML link in my code :
- Code: Select all
... $database_path = ereg_replace('(.*)htdocs', php_uname('n'), DATAFACE_SITE_PATH); $url = $record->getURL(array('-action'=>'edit')); $rel_link = getRelationships('table_main', 'relation_test'); if (count($rel_link) > 0) { $html_str .= '<td '.$color.'> <a href="http://'.$database_path.'/index.php?-table='.$rel_link[table]; foreach ($rel_link['fields'] as $rel_field => $map_field) { $html_str .= '&'.$rel_field.'='.$record->display($map_field); } $html_str .= '" class="unmarked_link">'.$val.'</td>'; } else { $html_str .= ' <td '.$color.'> <a href="'.$url.'" class="unmarked_link">'.$val.'</td>'; } ...
This method is not elegant, but I did not find another way…
Regards,
Patrice.