Setup Powerorm


We assume your project structure looks like this

        ---- Models
        ---- Migrations

Via composer (recommended):

composer require eddmash/powerorm

Or add this to the composer.json file:

"eddmash/powerorm": "1.1" (check latest version)

You could also Download or Clone package from github.

To rest of this guide assumes a plain php based project, no-frameworks used.

If you wish to see how to setup on specific frameworks please visit Frameworks Integrations

Create configuration

The orm requires a few Configurations, things like the database settings.

This will be added in the config.php

return [
    'database' => [
        'host' => '',
        'dbname' => 'tester',
        'user' => 'admin',
        'password' => 'admin',
        'driver' => 'pdo_pgsql',
    'dbPrefix' => 'demo_',
    'charset' => 'utf-8',

Load the orm

To load powerorm use the following code and pass the Configs needed for powerorm to work.

$configs = require_once 'config.php';

This should be load as early as possible, Place it a the beginning of your script.

Create application

So far we have not told the orm anything about our project, to do this We need to create an application class the will be used by the orm to get information about your php project.

If your project is namespaced as App; Create a class the extends the Eddmash\\PowerOrm\\Components\\AppComponent. This class should be placed on the same level as your models, migration folders.

namespace App;

use Eddmash\PowerOrm\BaseOrm;
use Eddmash\PowerOrm\Components\AppComponent;

class App extends AppComponent

    public function ready(BaseOrm $baseOrm)

    public function getDbPrefix()
        return "php_app";

Technically this file can be place anywhere in your project tree, To get this flexibility you need to override :

Register Application

Once we have the projects application class, we need to register it with the orm.

To register we add the App class we have created above into our configurations under the component configuration setting as shown below.

$config = [
    'database' => [
        'host' => '',
        'dbname' => 'tester',
        'user' => 'root',
        'password' => 'root1.',
        'driver' => 'pdo_mysql',
    'dbPrefix' => 'demo_',
    'charset' => 'utf-8',
    'timezone' => 'Africa/Nairobi',
    'components' => [

Create enable Powerorm on the command line

To be able to use the orm on the command line create a file on the same level as the composer.json file.

create file named pmanager.php and add the following .

use Eddmash\PowerOrm\Loader;
require_once 'vendor/autoload.php';
$configs = require_once 'config.php';

See all the available commands commands.

With that you ready.

Enjoy !