Is there a function like unloadModel in cakePHP that should be called to unload a model that was loaded using loadModel() function?
I found an unload method,
http://api20.cakephp.org/file/Cake/Model/BehaviorCollection.php#method-BehaviorCollectionunload
But it seems to be used for Behavior. Im new to cake. Is there a function like that or does it get automatically unloaded when the called action loses scope?
One more doubt; is using loadModel against MVC’s normal conventions? Does it have any adverse effects?
You do not need to unload your model. If you’re going to use the model throughout the entire Controller, then use the
$usesvariable:If you’re going to just use it in a specific action(s), use
loadModel:That’s it – no unloading necessary.
And no, it’s not against MVC imo and I have seen no adverse effects.
It’s VERY common to load a model. Example – most of my projects require a few “homepages” that have greatly-varying data from nearly ever model. In that case, I create a “DashboardsController”, which doesn’t even have a table – then I load each model when I need to access it’s data. (Or with
$usesif I’m going to use it’s data in all the actions).