Configuration

Configuration of SimpleAR is made through the Config instance you pass to the SimpleAR constructor.

$cfg = new SimpleAR\Config();
$cfg->myOption = 'myValue';

$app = new SimpleAR($cfg);

If you want to modify configuration after SimpleAR object has been instanciated, you can use SimpleAR::configure() method:

$app = new SimpleAR($cfg);

// ...

$cfg->myOption = 'myOtherValue';
$app->configure($cfg);

Available options

Database

  • charset: The charset to use to connect to database.
$cfg->charset = 'utf8';
  • buildForeignKey: A function used to construct foreign keys. It takes the model name as parameter and returns the foreign key.
$cfg->buildForeignKey = function($modelName) {
    return strtolower($modelName) . '_id';
};
  • classToTable: A function used to guess table name for a model. It takes the model class name as parameter and returns the table name.
$cfg->classToTable = 'strotolower';
  • databaseDateTimeFormat: The format to use when writing date in database.
$cfg->databaseDateTimeFormat = 'Y-m-d H:i';
  • doForeignKeyWork: A boolean to tell SimpleAR whether to perform ON DELETE CASCADE queries for database using storage engine that does not handle foreign keys (MyISAM for example).
  • dsn: The database dsn.
$cfg->dsn = array(
    'driver'   => 'mysql',
    'host'     => 'localhost',
    'name'     => 'dbname'
    'user'     => 'dbuser',
    'password' => 'dbpassword',
);
  • foreignKeySuffix: The suffix to use when constructing foreign keys. It can be used by buildForeignKey function.
// Want to use camelcase attribute instead of underscores?
$cfg->foreignKeySuffix = 'Id';

Localization

  • dateFormat: The format to use when using SimpleAR\DateTime as strings.
$cfg->dateFormat = 'd/m/Y'; // French format.

Model

  • convertDateToObject: A boolean to tell SimpleAR whether to automatically converting date fields into SimpleAR\DateTime instances.
  • modelClassSuffix: If you must use a suffix for your model classes (For example, in CodeIgniter, model classes must be suffixed by "_model"), specify it here. Otherwise, it would mess with foreign keys construction.
  • modelDirectory: A path or an array of pathes to the directory in which models are located.
$cfg->modelDirectory = array(
    'this/directory/',   // Will be checked by autoloader first.
    'and/this/one/too/', // Then, this path will.
);
  • primaryKey: The default primary key name.

General

  • debug: Are we in debug mode? If true, executed queries will be stored in Connection object.
  • queryOptionRelationSeparator: The character to use to separate relation names when building queries.
// You prefer a dot over a slash?
$cfg->queryOptionRelationSeparator = '.';
// Default values for this option:
$cfg->aliases = array(
    'SimpleAR\Orm\Model'   => 'SimpleAR\Model',
    'SimpleAR\Facades\DB'  => 'DB',
    'SimpleAR\Facades\Cfg' => 'Cfg',
);