->getLink()
Prev Next

->getLink()

->getLink() – fetch and return a related object

Synopsis

mixed $DB_DataObject->getLink ( string $column , string $table , string $key )

Description

Fetch a related object. This should be used in conjunction with a <dbname>.links.ini file configuration (see the introduction on linking for details on this).

You may also use this with all parameters to specify, the column, and related table and column.

Parameter

  • string $column - either column or column.xxxxx

  • string $table - name of table to look up value in

  • string $link - name of column in other table to match

Return value

mixed - object on success or FALSE on failure.

Note

This function can not be called statically.

Example

Getting the related object

<?php
$person 
= new DataObjects_Person;
$person->get(12);
$group = $person->getLink('group_owner');
echo 
$group->name;
$group = $person->getLink('colourid','hair');
?>

Resulting SQL

        
SELECT * FROM person WHERE id=12
SELECT * FROM group WHERE id=3
SELECT * FROM hair WHERE id=4

Prev DB_DataObject Next
Automatic Table Linking and Joins PEAR Manual ->getLinks()