Re: DB_Object linking question
| From: | Justin Patrin | Date: | Wed, 22 Dec 2004 21:59:35 +0000 |
| Subject: | Re: DB_Object linking question | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16422@lists.php.net to get a copy of this message | ||
DB_DataObject, not DB_Object
On Wed, 22 Dec 2004 11:39:34 -0800 (PST), l Burnerheimerton
<lburnerheimerton@yahoo.com> wrote:
> I have two tables, building and rooms. There can be more than one room per building. The
> structure is shown below in database.ini, as well as the database.links.ini and code.
>
> The problem is that the rooms are displaying but not the linked building names.
>
> Any ideas?
>
> code =======================================
> <?php
> require_once 'dao/Room.php';
You should be requiring DB/DataObject.php here
require_once 'DB/DataObject.php';
> $dbconfig = parse_ini_file('dao/db_dataobject.ini', true);
> // Load Database Settings (note main PEAR class is loaded by Room.php)
> foreach ($dbconfig as $class => $values) {
> $options = &PEAR::getStaticProperty($class, 'options');
> $options = $values;
> }
> $room = new DataObject_Room();
and using the factory here
$room =& DB_DataObject::factory('room');
> $room->building_ID = '2';
> $room->find();
> echo 'Room - Buildings:<br />';
> while ($room->fetch()) {
> $room->getLink('building_ID','building','ID');
getLink *returns* the linked dataobject. You also don't need the
second and third params as long as your db.links.ini is set up.
$building =& $room->getLink('building_ID');
> echo $room->number . ' - '. $building->name . '<br/>';
>
> }
> ?>
>
--
Justin Patrin