webscooby/yii-cycle

Cycle ORM adapter for Yii2.

1.0.4 2021-04-24 19:14 UTC

This package is auto-updated.

Last update: 2021-04-27 08:16:09 UTC


README

Cycle ORM adapter for Yii2 framework with debug panel.

Latest Stable Version Latest Unstable Version Build Status codecov

Installation

  1. Use composer.
composer require webscooby/yii-cycle
  1. Added configuration to your configs:
use Spiral\Database\Driver\MySQL\MySQLDriver;
use Webscooby\Yii\Cycle\Provider\CacheProvider;
use Webscooby\Yii\Cycle\Factory\OrmFactory;
use Webscooby\Yii\Cycle\Provider\ProviderInterface;
/**
* Example mysql configuration
 */
$_dbal = [
    'default' => 'mysql',
    'databases' => [
        'mysql' => [
            'connection' => 'mysql'
        ]
    ],
    'connections' => [
        'mysql' => [
            'driver' => MySQLDriver::class,
            'options' => [
                'connection' => 'mysql:host=127.0.0.1;dbname=dbname',
                'username' => 'username',
                'password' => 'password',
                'timezone' => 'Europe/Moscow'
            ]
        ]
    ]
];

/**
* Example adapter configuration
 */
$config = [
    'bootstrap' => [OrmFactory::class],
    'container' => [
        'definitions' => [
            ProviderInterface::class => [
                'class' => CacheProvider::class,
                'dbal' => $_dbal,
                'entities' => [
                    '@App/Entity' //namespace for your entities
                ],
                'migrations' => [
                    '@App/Migration' //path or alias to your migrations
                ],
                'migrationPath' => '@app/src/Migration', //default path or alias for new migrations
//                'migrationTable' => 'migration', //default - migration
                'migrationNamespace' => 'App\\Migration' //namespace for new migrations
            ]
        ]
    ]
];

Migrations

Use the following commands to manage migrations

  • Apply migrations
php yii migrator
  • Create migrations
php yii migrator/create <migrationName>
  • Cancel migrations
php yii migrator/down

More

  1. Spiral database configuration (DBAL)
  2. Cycle ORM Docs