PHPackages                             coreorm/framework - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. coreorm/framework

ActiveLibrary[Framework](/categories/framework)

coreorm/framework
=================

CoreORM PHP Framework For Relational Data Modelling

v1.3.6(11y ago)61071[1 issues](https://github.com/coreorm/coreorm/issues)MITPHPPHP &gt;=5.4.0

Since Aug 19Pushed 9y ago2 watchersCompare

[ Source](https://github.com/coreorm/coreorm)[ Packagist](https://packagist.org/packages/coreorm/framework)[ RSS](/packages/coreorm-framework/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (3)Versions (23)Used By (0)

CoreORM/Framework
=================

[](#coreormframework)

### What is this thing?

[](#what-is-this-thing)

Writing data layer is boring, trying to remember all the table names and all the fields in the table is impossible, writing SQL queries is painful and it's so easy to make mistakes!

I'm sure we've all been through this and we probably trying to avoid this as much as we can, yeah I know there a loads of active-record type ORM layers out there for php to use, but really can you remember all the fields? `$user->find('user_id=123')` really?!! And `echo $user->name` serious? I have to remember all the fields?

Nope, no, definitely not. So here I am introducing the simplified, light-weight and easy to use (well, code-autocompletion anyone?) ORM framework that totally does not suck.

### features

[](#features)

1. Thin models that can be used across different types of data source (MySQL/SQlite, will expand to cover more later)
2. DAO (Data Access Objects) that manages the thin models instead of models carrying the connections.
3. Out-of-the-box slave database support for large enterprise level data managements, supported by super simple APIs `$dao->readModel(\CoreORM\Model $model, $useSlave = true)`
4. Table relations in database mapped as object relations! `$passwordHash = $user->relationGetLogin()->getPassword();`
5. Zero SQL necessary! DAOs will automagically compose the SQL (and trust me, it's very fast) using the relations and criteria from the models.
6. Zero code necessary for models! They are actually generated based on a very simple configuration file (more details see the sections below).
7. Awesome performance - since the models are generated with all table/field information stored within the model, there's no need to describe table to generate queries or whatnot.
8. Extensibility - all models are crafted following proper OOD patterns, it's super easy to extend any model to add functionalities (having said that, you really don't need to do this at 90% of the time).
9. Less code, more accuracy (or actually it's 100% accuracy there). Since all tables are presented by models that contain proper getters and setters, you really don't need to remember the field name/table name at all, just type `$model->get` and your IDE should just give you a list of options to pick from.
10. You really want to write your own queries still? That's fine too, add your own DAO extending the base DAO, and you are set!

### compatibility

[](#compatibility)

The current version of CoreORM supports the following 2 database systems

- MySQL
- SQLite Future versions will add PostgreSQL and MS SQL server, etc.

The current version also ships with out of the box Laravel &amp; Slim framework compatibility.

For Laravel, since it contains db config already, simply add the following line in your `boostrap/start.php`, right before the final line `return $app`, add the following line:

```
\CoreORM\Core::integrateWithLaravel();

```

That's it!

For Slim framework, since database config is not part of the framework, you will have to add the database config in the following format before calling your Slim app:

```
$config = array(
    'coreorm' => array(
        'default_database' => 'example',
        'database' => array(
          'example' => array(
              'dbname' => 'coreorm_examples',
              'adaptor' => \CoreORM\Adaptor\Pdo::ADAPTOR_MYSQL,
              'user' => 'coreorm',
              'pass' => 'example',
              'host' => '127.0.0.1'
          )
        )
);
$app = new Slim($config);

```

Then right after that, ad the following line:

```
\CoreORM\Core::integrateWithSlim($app);

```

And you are set!

### How to include this package in your project

[](#how-to-include-this-package-in-your-project)

Simple add the following into your composer.json

```
    "require": {
            "coreorm/framework": "*"
    },
    "autoload": {
        "files": [
            "vendor/coreorm/framework/src/Core.php"
        ]
    }

```

### Install dependencies

[](#install-dependencies)

```
run
    composer install --prefer-dist

```

### NOTE: run composer install to enable autoload, if not all files are loading, run

[](#note-run-composer-install-to-enable-autoload-if-not-all-files-are-loading-run)

```
composer dump-autoload

```

### unit tests:

[](#unit-tests)

Please read the README.md file under `tests/` directory.

### setup the config this way (runtime).

[](#setup-the-config-this-way-runtime)

```
    setDbConfig('default_database', [default db adaptor name]);  // we need a default always
    // or, alternatively, use
    setDefaultDb([default db adaptor name]);
    // next, set up the database adaptors in this way:
    setDbConfig('database', array(
        [adaptor name] => (array) [$options]
    ));
    // use mysql as an example:
    setDbConfig('database', array(
        'main' => array(
            'dbname' => 'my_db_name',
            'user' => 'db_user_name',
            'pass' => 'db_password',
            'host' => '127.0.0.1',
            'port' => 3306, // optional
            'cache' => false, // default is false, true to enable cache in memory - NOTE: will increase memory usage
        ),
        'db1' => array(
            ...
        ),
    ));

```

\*\*\* NOTE: for Dynamodb, please follow Amazon's suggestion, have your credentials saved in `/home/[your user]/.aws/credentials`in the following format:

```
[my-dynamo-db]
aws_access_key_id=xxxxx
aws_secret_access_key=yyyyy

```

and ensure that your database setting follows the format:

```
    setDbConfig('database', array(
        'main' => array(
            'profile' => 'my-dynamo-db',
            'region' => 'my aws region',
            'adaptor' => CoreORM\Adaptor\Pdo::ADAPTOR_DYNAMODB
        )
    ));
    // then set default db
    setDefaultDb('main');

```

### generating models

[](#generating-models)

Run the following commands at project root

```
    chmod +x modeller

```

to generate model, make sure you put a config.php file somewhere, see example below:

```
