Skip to content

BOPOH/silex-idiorm-provider

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Idiorm Service Provider for Silex 2+

Provider for integrating Idiorm with Silex

Registering and configuration

$app->register(
    new \Idiorm\Silex\Provider\IdiormServiceProvider(),
    array(
        'idiorm.db.options' => array(
            'connection_string' => 'mysql:host=localhost;dbname=my_db',
            'username' => 'my_username',
            'password' => 'my_password',
            'id_column_overrides' => array(
                'table' =>  'primarykey',
            ),
        ),
    )
);

For more details on configuration array see: Idiorm configuration options

Usage in controller

To get all records for given table:

$app['idiorm.db']->for_table('my_table')->find_result_set();

For more query examples see: Idiorm querying

Multiple connections

To configure multiple connections use $app['idiorm.dbs.options']

$app['idiorm.dbs.options'] = array(
    'first_connection' => array(
        'connection_string' => 'mysql:host=localhost;dbname=my_db',
        'username' => 'my_username',
        'password' => 'my_password',
    ),
    'second_connection' => array(
        'connection_string' => 'sqlite:./example.db'
    )
);

$app['idiorm.dbs.options'] needs to be associative array, where keys will be connection names, and value will contain configuration array

To use connections in controller:

$app['idiorm.dbs']['first_connection']->for_table('my_table')->find_result_set();
$app['idiorm.dbs']['second_connection']->for_table('other_table')->find_result_set();

About

Silex service provider for Idiorm

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%