I maintain several cakephp sites that run different versions (from 2.4 to 4).
I recently updated the back office application to 4.3 and I wondered if there could be a way to have only one back office for all those sites.
Is there a way to load a different Datasources configuration according to the user id (or any other identifier) ?
These different sites share the same database structure? If not, I don’t see how one application could manage all of them.
Assuming that they are the same structure, you could certainly easily add code in your configuration files that look at the URL and use a different database for each different (sub)domain, for example. But basing it on the user… seems like a chicken and egg problem. Don’t you need to validate the user against the database before you can use the user details to choose which database to look at?
I did not think of this one
You could, presumably, have a standard “default” database connection for a database that just has your users in it, with each such record having the details for the database to actually connect to. Then, right after your authentication middleware runs, you’d have something that creates a new connection. All your other table classes could then reference that connection name in their defaultConnectionName
function. At least, it seems to me that this could work…
I think this might very well play some serious havoc with things like migrations, though.