dev-master
9999999-devA multi-site plugin for CakePHP 3.x, which lets you have host multiple sites from a single CakePHP install.
MIT
The Requires
- cakephp/cakephp ~3.2
- php >=5.4.0
multisite cakephp
Wallogit.com
2017 © Pedro Peláez
A multi-site plugin for CakePHP 3.x, which lets you have host multiple sites from a single CakePHP install.
A plugin that allows you to have a single Cakephp 3.x app which supports multiple websites, while being flexible enough that you can customize individual files on a per site basis., (*1)
For example: if a request is made to example.com, you might have some files like
APP/sites/example.com/config/app.php, and APP/sites/example.com/vendor/CakeDC/Users/src/Controllers/UsersController.php,
both of which would override the respective default file in the core APP on a per site basis., (*2)
In console run, (*3)
composer require codeblastr/multisite
Replace the first 6 lines of APP/config/bootstrap.php with the following., (*4)
<?php /** * Configure paths required to find CakePHP + general filepath * constants */ require __DIR__ . '/paths.php'; /** * Get multisites */ require ROOT . DS . 'sites' . DS . 'bootstrap.php';
In APP/composer.json add ```"CodeBlastrMultiSite\Console\AutoLoader::postAutoloadDump"to"post-autoload-dump"`` like this:, (*5)
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall",
"post-autoload-dump": [
"Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump",
"CodeBlastrMultiSite\\Console\\AutoLoader::postAutoloadDump"
]
},
In APP/config/app.php set App.paths.templates like this:, (*6)
'App' => [
'paths' => [
'templates' => [
ROOT . DS . SITE_DIR . DS . 'vendor' . DS . '%s' . DS . 'src' . DS . 'Template',
ROOT . DS . SITE_DIR . DS . 'src' . DS . 'Template' . DS,
APP . 'Template' . DS,
CORE_PATH . 'src'. DS . 'Template' . DS
],
],
],
In APP/src/View/AppView.php add both of the following:, (*7)
// near the top of the file, outside of class AppView()
use CodeBlastrMultiSite\View\MultisiteView;
// inside of class AppView()
/**
* Overwrites Cake/View::_paths()
*
* @param null $plugin
* @param bool $cached
* @return mixed
*/
protected function _paths($plugin = null, $cached = true)
{
$multisite = new MultisiteView();
$multisite->theme = $this->theme;
return $multisite->_paths($plugin, $cached);
}
Create a folder and file at APP/sites/bootstrap.php (these are examples, change the names to domains that you actually want to use), (*8)
<?php
/**
* Map domains this install will support, to where that site's files are located.
* The incoming request domain is on the left, the folder within the sites
* directory that the request maps to is on the right.
*/
$domains['example.com'] = 'example.com';
$domains['example-app.com'] = 'example-app-folder';
/**
* find the folder that is being requested by the domain
*/
if (!empty($domains[$_SERVER['HTTP_HOST']])) {
if (!defined('SITE_DIR')) {
// this is the site combined local and remote sites directory
define('SITE_DIR', 'sites/' . $domains[$_SERVER['HTTP_HOST']]);
}
}
If there is a plugin that you want individual sites to have access to customize or override you need to add it to the
autoload parameter of your main APP/composer.json file.
Formatted as "VendorName\\PluginName\\": "./SITE_DIR/vendor/[vendor name]/[plugin name]/src", for example..., (*9)
// APP/composer.json
"autoload": {
"psr-4": {
"App\\": "src",
"CodeBlastrMultiSite\\": "./SITE_DIR/vendor/codeblastr/multisite/src"
}
},
Anytime you add a new plugin to this autoload you'll need to run this in console, (*10)
composer dump-autoload
A multi-site plugin for CakePHP 3.x, which lets you have host multiple sites from a single CakePHP install.
MIT
multisite cakephp