The configuration consists of an associative array with the elements:
Database connection settings
Mapping configuration for each of the entity classes
This array is generally defined in a php script such as outlet-config.php. Outlet is then initialized with configuration array as the parameter:
Outlet::init(include APPROOT.'/outlet-config.php');
Here is a complete configuration:
Example 4.1. Sample configuration: outlet-config.php
return array(
'connection' => array(
'dsn' => 'mysql:host=myserver.com;dbname=mydb',
'username' => 'user',
'password' => 'pass',
'dialect' => 'mysql'
),
'classes' => array(
'Project' => array(
'table' => 'projects',
'props' => array(
'ID' => array('id', 'int', array('pk'=>true, 'autoIncrement'=>true)),
'Name' => array('name', 'varchar')
),
'associations' => array(
array('one-to-many', 'Bug', array('key'=>'ProjectID'))
)
),
'Bug' => array(
'table' => 'bugs',
'props' => array(
'ID' => array('id', 'int', array('pk'=>true, 'autoIncrement'=>true)),
'Title' => array('title', 'varchar'),
'ProjectID' => array('project_id', 'int'),
'Description' => array('description', 'varchar')
),
'associations' => array(
array('many-to-one', 'Project', array('key'=>'ProjectID'))
)
)
)
);array( 'dsn' => 'mysql:host=myhost.com;dbname=testdb', 'username' => 'testdbuser', 'password' => 'testdbpass', 'dialect' => 'mysql' )
A PDO connection string
A username if the database driver requires it
A password if the database driver requires it
The dialect to use. It can be mysql, mssql, or sqlite.
array(
'User' => array(
'table' => 'users', // name of the database table
'props' => array(...), // properties mappings
'associations' => array(...) // relationships mappings
),
'Project' =>
...
)An array of class mappings indexed by the name of the entity class. Each class mapping is an associative array with the elements:
Name of the database table or view that this entity maps to
An array of property mappings
Optional. An array of association mappings
Optional. The noun to use when referring to more than one. This is the name used by default on association methods if there's no 'plural' setting set on the association itself. Defaults to the entity name plus an 's'.
array(
'ID' => array('user_id', 'int', array('pk'=>true, 'autoIncrement'=>true)),
'FirstName' => array('first_name', 'varchar'),
...
)The indexes are the properties of the class being mapped.
The first element of each mapping is the name of the column.
The second is the column type, which can be either int or varchar.
The third element is an array of optional settings:
Whether this field is (part of) the primary key. Defaults to false.
Whether this field is automatically incremented by the database. Defaults to false.
A default value. It can be an integer or a string.
A default sql expression or function, such as NOW().
array(
array('one-to-many', 'Bug', array('key'=>'BugID')),
array('many-to-one', 'Project', array('key'=>'ProjectID')),
...
)The first element of an association mapping is the type, it can be either one-to-many or many-to-one.
The second element is the entity class that this relation refers to (related entity).
The third element is a set of options which differ depending on the type of association.
The name of the property on the related entity that contains the primary key of this entity.
Optional. Defaults to the name of the related entity.
The name to give the relationship. If this association defines the relationship between a bug and the people who are assigned to it (one-to-many from Bug to User), and you set the name to 'Assignee', the method names on the bug object will be 'getAssignees', 'setAssignees', and 'addAssignee'.
Optional. The noun to use when creating methods that return more than one entity. Only necessary for associations that use something other than the entity name (such as 'Sender' or 'Creator' for a an association with a 'User'). Defaults to the association name plus an 's'.
The name of the property on this entity that contains the primary key of the related entity.
Optional. Defaults to the name of the related entity.
The name to give the relationship. If this association defines the relationship between a bug and the user who reported it (many-to-one from Bug to User), and you set the name to 'Reporter', the method names on the bug object will be 'getReporter' and 'setReporter'.
Optional. Defaults to false.
Whether to allow this relationship to be optional (allow null).