9.3. Xyster_Orm_Mapper

The Xyster_Orm_Mapper class is intended to connect to SQL databases. You can extend Xyster_Orm_Mapper_Abstract to create a mapper that connects to an LDAP server, parses an XML document, calls web services, and so on.

You need to set up the database connection to Xyster_Orm_Mapper before any operations are performed with Xyster_Orm. Simply pass the connection settings to the dsn method of Xyster_Orm_Mapper.

Xyster_Orm_Mapper::dsn('myDb', 'Pdo_Mysql', array('host' => '',
    'username' => 'webuser',
    'password' => 'xxxxxxxx',
    'dbname' => 'test'));

You can also pass a Zend_Db_Adapter_Abstract object instead of the driver type and options.

$db = new Zend_Db_Adapter_Pdo_Mysql(array('host' => '',
    'username' => 'webuser',
    'password' => 'xxxxxxxx',
    'dbname' => 'test'
Xyster_Orm_Mapper::dsn('myDb', $db);

The Xyster_Orm_Mapper class has the ability to cache the metadata it retrieves for tables, avoiding repeat trips to the data store. A Zend_Cache_Core object can be passed to the Xyster_Orm_Mapper_Factory instance that creates the mappers.

$frontendOptions = array('automatic_serialization' => true);
$backendOptions = array('cacheDir' => 'cacheDir');
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);

$orm = Xyster_Orm::getInstance();
$mf = $orm->getMapperFactory();

Alternatively, you can specify a Zend_Registry key in the options array of the mapper itself.

// let's pretent $cache is the Zend_Cache object we factoried a minute ago
Zend_Registry::set('myCache', $cache);

class SomethingMapper extends Xyster_Orm_Mapper
	// protected properties like $_domain, etc.
	protected $_options = array('metadataCache' => 'myCache');