phpcakephpcakephp-2.0

Load multiple models in a controller


I want to load multiple models in a particular function in a controller?

Expecting repeatatively $this->loadModel('ModelName') method.


Solution

  • I have resolved my problem, it's a simple way by passing an array of ModelNames in $this->loadModel(); function.

    $this->loadModel('model1', 'model2', 'model3', ...);
    

    And you want to load multiple models for whole controller then you can :

    public $uses = array('model1', 'model2', 'model3', .... );