Reputation: 79
I have two separate CakePHP 3.1 apps that each use the same database, but display the information in very different ways. To reduce code duplication, I'm extracting most of the models into a plugin. The controllers differ wildly from each other, so I am not including any of them in the plugin at the moment. What is the proper way to specify that the primary model for a controller resides in a plugin?
In previous versions of CakePHP, the answer would have been to use the $uses
property of the controller, but as far as I can tell this is no longer an option. As best I can tell, the only way to make the plugin model accessible from all actions is to do a loadModel
in the controller's initialize method. Is that the optimal way to handle this situation?
Upvotes: 0
Views: 51
Reputation: 5099
Looking at the source of the Controller class, it would seem that setting public $modelClass = 'Plugin.Model'; may work. __construct determines what it thinks would be the model, and then calls modelAwareTrait::_setModelClass with that, but that function doesn't actually set it if there's something there already.
Upvotes: 1