How to change database source from Controller and Model both?

I have to use two database connections one for select and another for insert/update etc. The queries are written in Model but at some places in the Controller files as well for select operation. How can i manage the connections from both the places for all the operations select, insert, update, delete.
I hope i have explained the issue.

This is urgent.

Thanking you.

Version: cakephp v3.4

I don’t have experience setting and using different db connections but I know the connection can be part of a table configuration. So I would do something like this:

  • Build a base table class that established the associations and other features I wanted for this table in general (call it TBase for this discussion)
  • Build two table classes that extend TBase each one configured to use a different connection (call them TSelect and TUpdate for discussion)

Now, just use the variant you need for your task

$TSelect = TableRegistry::getTableLocator()->get('TSelect');

$TUpdate = TableRegistry::getTableLocator()->get('TUpdate');
$entity = $TUpdate->patchEntity($entity, $this->request->getData());