Skip to content

Instantly share code, notes, and snippets.

View chopstik's full-sized avatar

the chopstik |/ chopstik

View GitHub Profile
@chopstik
chopstik / Application.php
Created November 13, 2019 09:57
Change database in CakePHP 3 based on request data
<?php
/*
* Allow development users to switch between databases
* ...add to \App\Application::middleware
* */
$middlewareQueue->add(function (ServerRequest $request, Response $response, $next) {
$isPreviouslyAliased = false;
@chopstik
chopstik / UpdateCounterCachesShell.php
Last active April 19, 2022 00:07
CakePHP Shell to make use of UpdateCounterCache.php
<?php
namespace App\Shell;
use Cake\Console\Shell;
/**
* UpdateCounterCaches shell command.
*/
class UpdateCounterCachesShell extends Shell
@chopstik
chopstik / UpdateCounterCache.php
Last active April 21, 2020 02:16 — forked from hmic/UpdateCounterCache.php
Cake3 update counter caches for association
<?php
namespace App\Model\Table\Traits;
use Cake\ORM\Query;
trait UpdateCounterCacheTrait
{