May 14, 2014

9:37 am
In this article, we are going to discuss about How to load the models inside the another models. A model notifies its associated views and controllers when there has been a change in its state. This notification allows the views to produce updated output, and the controllers to change the available set of commands. In some cases an MVC implementation might instead be "passive," so that other components must poll the model for updates rather than being notified.

This is a really quick help that I'm always looking up is how to load CakePHP Models from within another Model, this is currently using version 2.x.

// the other model to load & use
App::uses('AnotherModel', 'Model');

class MyModel extends AppModel {

public $name = 'MyModel';

public function test() {
// load the Model
$anotherModel = new AnotherModel();
// use the Model

Instead of declaring uses at the top you can also import the Model class when you want to use it:

$anotherModel = new AnotherModel();


Post a Comment