I am new to Cakephp and started with cake3.
A question arises on me is that which approach is the best from the performance sense to get an instance of a table in CakePHP-3.0 which is not a controller's default one between loadModel or TableRegistry.
Such as:
1. $this->loadModel('Articles');
OR
2. TableRegistry::get('Articles');
I read Cake-Doc for loadModel and TableRegistry. Confusion comes from here
Thanks in advance
When in a controller, it is better to use loadModel()
. The reason is that it is easier to mock when doing unit testing.
It also sets the $this->[MyTable]
variable according to the table that has be loaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With