9.4. Xyster_Orm_Entity

Before we go into how to load entities, let's go over how to use an entity that's loaded. For example's sake, let's say that we've loaded this database record as an entity from the person table:

person_id= 1
name= Luke Skywalker
affiliation= Rebel
alignment= good
gender= M
race= Human

Let's say this record's information is now in a person entity ($luke).

<?php
echo $luke->personId;// prints 1
print_r($luke->getPrimaryKey()); // gives us array(‘personId’ => 1)
echo $luke->name;// prints 'Luke Skywalker'
echo $luke->getPersonId();// prints 1
echo $luke->getName();// prints 'Luke Skywalker'
$luke->affiliation = 'Jedi';
$luke->setAffiliation('Jedi');
$array = $luke->toArray();// returns array('personId'=>1, 'name'=>'Luke Skywalker', etc.
            

You can retrieve the primary key for an entity with the getPrimaryKey method. It returns an associative array with field names and values. Alternatively, getPrimaryKeyAsCriterion returns a Xyster_Data_Criterion object for the primary key. Fields on the entity can be accessed like properties or by method calls. Fields can also be set with either syntax.