In Cake 2.x
, models are lazy loaded in the controller if the name of controller and model follow a convention - pluralized controller, singularized model.
However, I have a scenario where my controller and model don't follow this convention. How do I load the model for each method of the controller?
One way is to use loadModel
method of the controller. But I will have to repeat it in each method.
One way is to use loadModel method of controller. But I will have to repeat it in each method.
https://book.cakephp.org/2.0/en/controllers.html#request-life-cycle-callbacks
Use beforeFilter().
However, this sounds like you're doing stuff in a controller that should be done in another controller that reflects what actually is inside the domain of the model you're using.