2017 © Pedro Peláez
 

cakephp-plugin cake-multi-tenant

image

waldemarnt/cake-multi-tenant

  • Friday, December 18, 2015
  • by waldemarnt
  • Repository
  • 0 Watchers
  • 2 Stars
  • 53 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Multi tenant CakePHP (2.x) Plugin

The Multi Tenant plugin allows an application to be separated in several applications having own routes, sharing the same code and different databases (or the same)., (*1)

Installing

Via composer:, (*2)

    composer require waldemarnt/cake-multi-tenant

Or just download the repository here, (*3)

Configuration

bootstrap.php configuration

Just call the plugin below the Dispatch configuration in your boostrap, enable routes and boostrap., (*4)

    CakePlugin::load('CakeMultiTenant', array('routes' => true, 'bootstrap' => true));

core.php configuration

In the core file you will need add the several properties. Current tenant (or default)., (*5)

    Configure::write('Config.current_tenant', 'example');

Note: current tenant will be the active tenant, you can use this information to know which tenant is active., (*6)

Tenant configuration will be an array using the tenant name as a index and connection_name will be the name of database connection that the tenant will use., (*7)

    Configure::write('Config.multi_tenant_config', [
            'example' => [
                'name' => 'Example Tenant',
                'connection_name' => 'my_custom_db_connection'
            ],
            'waldemar' => [
                'name' => 'Waldemar',
                'connection_name' => 'my_other_db_connection'
            ]
        ]
    );

database.php configuration

In the database file you just need add the configuration for each tenant like this:, (*8)

    public $my_custom_db_connection = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => '172.17.0.3',
        'login' => 'root',
        'password' => 'root',
        'database' => 'db_one',
        'prefix' => '',
        //'encoding' => 'utf8',
    );

    public $my_other_db_connection = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => '172.17.0.3',
        'login' => 'root',
        'password' => 'root',
        'database' => 'db_two',
        'prefix' => '',
        //'encoding' => 'utf8',
    );

AppModel.php configuration

Just extend your AppModel from MultiTenantAppModel, the MultiTenantAppModel that handles the database switch when the model will be created., (*9)

    App::uses('MultiTenantAppModel', 'CakeMultiTenant.Model');

    class AppModel extends MultiTenantAppModel {

    }

AppController.php

In the AppController you will need configure two stuffs, Html Helper and AuthComponent (if you need auth :D). Html helper configuration:, (*10)


public $helpers = array( 'Html' => array('className' => 'CakeMultiTenant.MultiTenantHtml'), );

AuthComponent configuration:, (*11)

    public $components = array(
        'Auth' => [
            'className' => 'CakeMultiTenant.MultiTenantAuth'
    );

Note: you can add loginAction and LoginRedirect configurations in the Auth component there's no change in the original behavior of the component., (*12)

Version

0.*, (*13)

The Versions

18/12 2015

dev-master

9999999-dev

  Sources   Download

The Requires

 

by Waldemar Neto

18/12 2015

v0.0.7

0.0.7.0

  Sources   Download

The Requires

 

by Waldemar Neto

14/12 2015

v0.0.6

0.0.6.0

  Sources   Download

The Requires

 

by Waldemar Neto

14/12 2015

v0.0.5

0.0.5.0

  Sources   Download

The Requires

 

by Waldemar Neto

06/12 2015

v0.0.4

0.0.4.0

  Sources   Download

The Requires

 

by Waldemar Neto

06/12 2015

v0.0.3

0.0.3.0

  Sources   Download

The Requires

 

by Waldemar Neto

06/12 2015

v0.0.2

0.0.2.0

  Sources   Download

The Requires

 

by Waldemar Neto

06/12 2015

v0.0.1

0.0.1.0

  Sources   Download

The Requires

 

by Waldemar Neto