Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1168

Joomla! 5.x Coding • Re: Reading data from an external database in a model

$
0
0
You can pass the database instance when creating the model. For example, when creating the model using the MVC factory:

Code:

$model = $factory->createModel('Items', 'Administrator', ['dbo' => $externalDb]);
But this is deprecated. Another option is to use the setter method on the model instance:

Code:

$model = $factory->createModel('Items', 'Administrator');$model->setDatabase($externalDb);
This method can technically also be called from within the model's constructor, if you are building the DB instance inside the model itself instead of injecting it.

Statistics: Posted by SharkyKZ — Sun Sep 01, 2024 10:56 am



Viewing all articles
Browse latest Browse all 1168

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>