php - How to set Data source within Table Model file In Cake 3 ? -


in cake 2 set $this->setdatasource('database_name'); , create property of same name in config\database.php

in cakephp 3 have added additional datasource in app.php after default unable use $this->setdatasource( within initialize. unknown method "setdatasource".

in cakephp 3.x, datasources "connections". can set connection on table so:

use cake\orm\tableregistry; use cake\datasource\connectionmanager;  $connection = connectionmanager::get('default'); $table = tableregistry::get('users'); $table->setconnection($connection); 

if want table use different connection, can use initialize hook set it.

you can set connection specific query.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -