waldemarnt/cake-multi-tenant
Composer 安装命令:
composer require waldemarnt/cake-multi-tenant
包简介
README 文档
README
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).
##Installing Via composer:
composer require waldemarnt/cake-multi-tenant
Or just download the repository here
##Configuration
###bootstrap.php configuration
Just call the plugin below the Dispatch configuration in your boostrap, enable routes and boostrap.
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).
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.
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.
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:
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.
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:
public $helpers = array(
'Html' => array('className' => 'CakeMultiTenant.MultiTenantHtml'),
);
AuthComponent configuration:
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.
Version
0.*
waldemarnt/cake-multi-tenant 适用场景与选型建议
waldemarnt/cake-multi-tenant 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 waldemarnt/cake-multi-tenant 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 waldemarnt/cake-multi-tenant 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 75
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-12-06